Skip to content

Commit

Permalink
Merge branch 'master' into 613_fix_pom_error_non_java
Browse files Browse the repository at this point in the history
  • Loading branch information
zabil committed Jun 12, 2021
2 parents 7283456 + ea596a1 commit 4e874db
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
2 changes: 0 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 14 additions & 9 deletions src/execution/gaugeExecutor.ts
Expand Up @@ -48,10 +48,10 @@ export class GaugeExecutor extends Disposable {
}

public execute(spec: string, config: ExecutionConfig): Thenable<any> {
return new Promise((resolve, reject) => {
return new Promise((resolve) => {
if (this.executing) {
reject(new Error('A Specification or Scenario is still running!'));
return;
window.showErrorMessage('A Specification or Scenario is still running!');
return resolve(undefined);
}
try {
this.executing = true;
Expand Down Expand Up @@ -151,14 +151,16 @@ export class GaugeExecutor extends Disposable {
if (activeTextEditor) {
let doc = activeTextEditor.document;
if (!extensions.includes(extname(doc.fileName))) {
return Promise.reject(new Error(`No specification found. Current file is not a gauge specification.`));
window.showErrorMessage('No specification found. Current file is not a gauge specification.');
return Promise.resolve(undefined);
}
return this.execute(doc.fileName, new ExecutionConfig()
.setStatus(doc.fileName)
.setProject(ProjectFactory.getProjectByFilepath(doc.uri.fsPath))
);
} else {
return Promise.reject(new Error(`A gauge specification file should be open to run this command.`));
window.showErrorMessage('A gauge specification file should be open to run this command.');
return Promise.resolve(undefined);
}
}

Expand All @@ -169,7 +171,8 @@ export class GaugeExecutor extends Disposable {
let spec = activeTextEditor.document.fileName;
let lc = clientsMap.get(window.activeTextEditor.document.uri.fsPath).client;
if (!extensions.includes(extname(spec))) {
return Promise.reject(new Error(`No scenario(s) found. Current file is not a gauge specification.`));
window.showErrorMessage('No scenario(s) found. Current file is not a gauge specification.');
return;
}
return this.getAllScenarios(lc, atCursor).then((scenarios: any): Thenable<any> => {
if (atCursor) {
Expand All @@ -178,10 +181,11 @@ export class GaugeExecutor extends Disposable {
return this.executeOptedScenario(scenarios);
}, (reason: any) => {
window.showErrorMessage(`found some problems in ${spec}. Fix all problems before running scenarios.`);
return Promise.reject(reason);
return Promise.resolve(undefined);
});
} else {
return Promise.reject(new Error(`A gauge specification file should be open to run this command.`));
window.showErrorMessage('A gauge specification file should be open to run this command.');
return Promise.resolve(undefined);
}
}

Expand Down Expand Up @@ -259,7 +263,8 @@ export class GaugeExecutor extends Disposable {
);
}
}, (reason: any) => {
return Promise.reject(reason);
window.showErrorMessage(reason);
return Promise.resolve(undefined);
});
}

Expand Down
26 changes: 19 additions & 7 deletions test/execution/execution.test.ts
Expand Up @@ -2,13 +2,22 @@ import * as assert from 'assert';
import * as path from 'path';
import { commands, Uri, window, workspace } from 'vscode';
import { GaugeVSCodeCommands } from '../../src/constants';
import { createSandbox } from 'sinon';

let testDataPath = path.join(__dirname, '..', '..', '..', 'test', 'testdata', 'sampleProject');

suite('Gauge Execution Tests', () => {
setup(async () => { await commands.executeCommand('workbench.action.closeAllEditors');
await commands.executeCommand("vscode.openFolder", Uri.file( path.join(__dirname, '..', '..', '..', 'test', 'testdata')));
});
let sandbox;

teardown(() => {
sandbox.restore();
});

setup(async () => {
sandbox = createSandbox();
await commands.executeCommand('workbench.action.closeAllEditors');
await commands.executeCommand("vscode.openFolder", Uri.file( path.join(__dirname, '..', '..', '..', 'test', 'testdata')));
});

let assertStatus = (status, val = true) => {
let logDoc = workspace.textDocuments.find((x) => x.languageId === "Log");
Expand Down Expand Up @@ -75,15 +84,18 @@ suite('Gauge Execution Tests', () => {
});

test('should reject execution when another is already in progress', async () => {
let expectedErrorMessage;
sandbox.stub(window, 'showErrorMessage').callsFake((args) => expectedErrorMessage = args );

let spec = path.join(testDataPath, 'specs', 'example.spec');
let doc = await workspace.openTextDocument(Uri.file(spec));
await window.showTextDocument(doc);
commands.executeCommand(GaugeVSCodeCommands.ExecuteAllSpecs);
try {
await commands.executeCommand(GaugeVSCodeCommands.Execute, spec);
throw new Error("Expected simultaneous runs to reject");
} catch (err) {
assert.equal(err.message, "A Specification or Scenario is still running!");
throw new Error("Must not run new tests when others are already in progress");
} catch {
assert.equal(expectedErrorMessage, "A Specification or Scenario is still running!");
}
}).timeout(20000);
});
});

0 comments on commit 4e874db

Please sign in to comment.