Skip to content

Commit

Permalink
fixed workers tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DavertMik committed Jan 19, 2025
1 parent 87608a4 commit 5b4b9a6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
5 changes: 5 additions & 0 deletions lib/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -70,6 +74,7 @@ class Result {

simplify() {
return {
hasFailed: this.hasFailed,
stats: this.stats,
duration: this.duration,
tests: this._tests.map(test => test.simplify()),
Expand Down
2 changes: 1 addition & 1 deletion lib/workers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 14 additions & 14 deletions test/unit/worker_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
})
})
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
})
})
Expand Down Expand Up @@ -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()
})
})
Expand All @@ -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()
})
})
Expand Down Expand Up @@ -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()
})
})
Expand Down

0 comments on commit 5b4b9a6

Please sign in to comment.