diff --git a/lib/result.js b/lib/result.js index 75130d6d5..a9b6ff447 100644 --- a/lib/result.js +++ b/lib/result.js @@ -31,6 +31,10 @@ class Result { this._endTime = new Date() } + get hasFailed() { + return this.tests.some(test => test.state === 'failed') + } + get tests() { return this._tests } @@ -70,6 +74,7 @@ class Result { simplify() { return { + hasFailed: this.hasFailed, stats: this.stats, duration: this.duration, tests: this._tests.map(test => test.simplify()), diff --git a/lib/workers.js b/lib/workers.js index 52607eb35..74ab182b6 100644 --- a/lib/workers.js +++ b/lib/workers.js @@ -443,7 +443,7 @@ class Workers extends EventEmitter { _finishRun() { event.dispatcher.emit(event.workers.after, { tests: this.workers.map(worker => worker.tests) }) - if (this.isFailed()) { + if (Container.result().hasFailed) { process.exitCode = 1 } else { process.exitCode = 0 diff --git a/test/unit/worker_test.js b/test/unit/worker_test.js index f1cde53a6..fe051ca45 100644 --- a/test/unit/worker_test.js +++ b/test/unit/worker_test.js @@ -28,8 +28,8 @@ describe('Workers', function () { workers.run() - workers.on(event.all.result, status => { - expect(status).equal(false) + workers.on(event.all.result, result => { + expect(result.hasFailed).equal(false) expect(passedCount).equal(5) expect(failedCount).equal(3) done() @@ -63,9 +63,9 @@ describe('Workers', function () { workers.run() - workers.on(event.all.result, status => { + workers.on(event.all.result, result => { expect(workers.getWorkers().length).equal(2) - expect(status).equal(true) + expect(result.hasFailed).equal(false) done() }) }) @@ -100,8 +100,8 @@ describe('Workers', function () { passedCount += 1 }) - workers.on(event.all.result, status => { - expect(status).equal(false) + workers.on(event.all.result, result => { + expect(result.hasFailed).equal(false) expect(passedCount).equal(3) expect(failedCount).equal(2) done() @@ -135,9 +135,9 @@ describe('Workers', function () { workers.run() - workers.on(event.all.result, status => { + workers.on(event.all.result, result => { expect(workers.getWorkers().length).equal(2) - expect(status).equal(true) + expect(result.hasFailed).equal(false) done() }) }) @@ -170,9 +170,9 @@ describe('Workers', function () { workers.run() - workers.on(event.all.result, status => { + workers.on(event.all.result, result => { expect(workers.getWorkers().length).equal(2) - expect(status).equal(true) + expect(result.hasFailed).equal(false) done() }) }) @@ -199,8 +199,8 @@ describe('Workers', function () { workers.run() recorder.add(() => share({ fromMain: true })) - workers.on(event.all.result, status => { - expect(status).equal(true) + workers.on(event.all.result, result => { + expect(result.hasFailed).equal(false) done() }) }) @@ -258,9 +258,9 @@ describe('Workers', function () { workers.run() - workers.on(event.all.result, status => { + workers.on(event.all.result, result => { expect(workers.getWorkers().length).equal(8) - expect(status).equal(true) + expect(result.hasFailed).equal(false) done() }) })