Skip to content

Commit

Permalink
Merge pull request #174 from gemini-testing/fix/passing-of-error
Browse files Browse the repository at this point in the history
fix: correct passing of errors from subprocesses to the main process
  • Loading branch information
eGavr authored Aug 18, 2017
2 parents cd5b7a5 + 13e4c17 commit b7b0afd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
8 changes: 4 additions & 4 deletions lib/runner/mocha-runner/mocha-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,16 @@ module.exports = class MochaAdapter extends EventEmitter {
return this._browserAgent.getBrowser()
.then((browser) => this._browser = browser) // we need to save browser to use it in a proxy reporter
.then(() => {
const browser = this._browser;
const fullTitle = test.fullTitle();
const browser = this._browser;
const start = Date.now();

return q.ninvoke(workers, 'runTest', fullTitle, {browserId: browser.id, sessionId: browser.sessionId})
.then((data) => this._extendTestInfo(test, data.meta))
.catch((data) => {
this._extendTestInfo(test, data.meta);
.catch((err) => {
this._extendTestInfo(test, err.meta);

return q.reject(data.err);
return q.reject(err);
})
.finally(() => {
test.time = Date.now() - start;
Expand Down
2 changes: 1 addition & 1 deletion lib/worker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ exports.syncConfig = (config, cb) => {
exports.runTest = (fullTitle, options, cb) => {
hermione.runTest(fullTitle, options)
.then((data) => cb(null, data))
.catch((data) => cb(data));
.catch((err) => cb(err));
};
2 changes: 1 addition & 1 deletion lib/worker/runner/mocha-runner/mocha-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ module.exports = class MochaAdapter extends EventEmitter {
this._mocha.run(() => {
const meta = this._browser.meta;

return this._fail ? defer.reject({err: this._fail, meta}) : defer.resolve({meta});
return this._fail ? defer.reject(_.extend(this._fail, {meta})) : defer.resolve({meta});
});

return defer.promise;
Expand Down
13 changes: 7 additions & 6 deletions test/lib/runner/mocha-runner/mocha-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ describe('mocha-runner/mocha-adapter', () => {
describe('run', () => {
function stubWorkers() {
const stub = sandbox.stub();
return {runTest: stub.yields.apply(stub, arguments)};
const args = arguments.length ? arguments : [null, {}];
return {runTest: stub.yields.apply(stub, args)};
}

it('should request browser before suite execution', () => {
Expand Down Expand Up @@ -463,7 +464,7 @@ describe('mocha-runner/mocha-adapter', () => {

MochaStub.lastInstance.updateSuiteTree((suite) => suite.addTest());

return mochaAdapter.run()
return mochaAdapter.run(stubWorkers())
.then(() => {
assert.calledOnce(logger.warn);
assert.calledWithMatch(logger.warn, /some-error/);
Expand All @@ -480,7 +481,7 @@ describe('mocha-runner/mocha-adapter', () => {

MochaStub.lastInstance.updateSuiteTree((suite) => suite.addTest());

return mochaAdapter.run().then(() => {
return mochaAdapter.run(stubWorkers()).then(() => {
assert.calledOnceWith(browserAgent.freeBrowser, browser, {force: false});
});
});
Expand All @@ -492,7 +493,7 @@ describe('mocha-runner/mocha-adapter', () => {
MochaStub.lastInstance.updateSuiteTree((suite) => suite.addTest());
mochaAdapter.emit(RunnerEvents.TEST_FAIL, {err: {message: 'other-error'}});

return mochaAdapter.run().then(() => {
return mochaAdapter.run(stubWorkers()).then(() => {
assert.calledOnceWith(browserAgent.freeBrowser, sinon.match.any, {force: false});
});
});
Expand All @@ -504,7 +505,7 @@ describe('mocha-runner/mocha-adapter', () => {
MochaStub.lastInstance.updateSuiteTree((suite) => suite.addTest());
mochaAdapter.emit(RunnerEvents.TEST_FAIL, {err: {message: 'SOME-ERROR'}});

return mochaAdapter.run().then(() => {
return mochaAdapter.run(stubWorkers()).then(() => {
assert.calledOnceWith(browserAgent.freeBrowser, sinon.match.any, {force: true});
});
});
Expand Down Expand Up @@ -540,7 +541,7 @@ describe('mocha-runner/mocha-adapter', () => {

MochaStub.lastInstance.updateSuiteTree((suite) => suite.addTest().onFail(testFailSpy));

return mochaAdapter.run(stubWorkers({err: {some: 'err'}}))
return mochaAdapter.run(stubWorkers({some: 'err'}))
.then(() => {
assert.calledOnce(testFailSpy);
assert.calledWithMatch(testFailSpy, {error: {some: 'err'}});
Expand Down

0 comments on commit b7b0afd

Please sign in to comment.