Skip to content
This repository has been archived by the owner on Dec 18, 2019. It is now read-only.

Commit

Permalink
wait until all events has been sent to the main process - refs webdri…
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed Dec 7, 2016
1 parent 4eeea87 commit 58709f3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class JasmineAdapter {
this.jrunner.execute()
})
await executeHooksWithArgs(this.config.after, [result, this.capabilities, this.specs])
await this.reporter.waitUntilSettled()
return result
}

Expand Down
19 changes: 18 additions & 1 deletion lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ class JasmineReporter {
this._specs = specs
this._parent = []
this._failedCount = 0

this.sentMessages = 0 // number of messages sent to the parent
this.receivedMessages = 0 // number of messages received by the parent
}

suiteStarted (suite = {}) {
Expand Down Expand Up @@ -70,13 +73,27 @@ class JasmineReporter {
}

message.runner[this._cid] = this._capabilities
this.send(message)
this.sentMessages++
this.send(message, null, {}, () => ++this.receivedMessages)
}

send (...args) {
process.send.apply(process, args)
}

/**
* wait until all messages were sent to parent
*/
waitUntilSettled () {
return new Promise((resolve) => {
const interval = setInterval(() => {
if (this.sentMessages !== this.receivedMessages) return
clearInterval(interval)
resolve()
}, 100)
})
}

getFailedCount () {
return this._failedCount
}
Expand Down
22 changes: 22 additions & 0 deletions test/reporter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,28 @@ describe('jasmine reporter', () => {
})
})

it('should wait until all events were sent', () => {
const start = (new Date()).getTime()

reporter.specStarted()
reporter.specDone({
status: 'passed',
description: 'my test',
id: 4
})

setTimeout(() => {
send.args[0][3]()
send.args[1][3]()
send.args[2][3]()
}, 500)

return reporter.waitUntilSettled().then(() => {
const end = (new Date()).getTime();
(end - start).should.be.greaterThan(500)
})
})

describe('provides a fail counter', () => {
it('should have right fail count at the end', () => {
reporter.getFailedCount().should.be.exactly(2)
Expand Down

0 comments on commit 58709f3

Please sign in to comment.