diff --git a/lib/runner/mocha-runner/mocha-adapter.js b/lib/runner/mocha-runner/mocha-adapter.js index f47ab6706..21f5491df 100644 --- a/lib/runner/mocha-runner/mocha-adapter.js +++ b/lib/runner/mocha-runner/mocha-adapter.js @@ -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; diff --git a/lib/worker/index.js b/lib/worker/index.js index 68013373a..085123173 100644 --- a/lib/worker/index.js +++ b/lib/worker/index.js @@ -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)); }; diff --git a/lib/worker/runner/mocha-runner/mocha-adapter.js b/lib/worker/runner/mocha-runner/mocha-adapter.js index b50d6b9f5..eb11655bb 100644 --- a/lib/worker/runner/mocha-runner/mocha-adapter.js +++ b/lib/worker/runner/mocha-runner/mocha-adapter.js @@ -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; diff --git a/test/lib/runner/mocha-runner/mocha-adapter.js b/test/lib/runner/mocha-runner/mocha-adapter.js index 26ea981f6..af5ebdd03 100644 --- a/test/lib/runner/mocha-runner/mocha-adapter.js +++ b/test/lib/runner/mocha-runner/mocha-adapter.js @@ -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', () => { @@ -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/); @@ -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}); }); }); @@ -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}); }); }); @@ -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}); }); }); @@ -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'}});