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

Commit 58709f3

Browse files
wait until all events has been sent to the main process - refs webdriverio/webdriverio#1713
1 parent 4eeea87 commit 58709f3

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

lib/adapter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class JasmineAdapter {
119119
this.jrunner.execute()
120120
})
121121
await executeHooksWithArgs(this.config.after, [result, this.capabilities, this.specs])
122+
await this.reporter.waitUntilSettled()
122123
return result
123124
}
124125

lib/reporter.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ class JasmineReporter {
55
this._specs = specs
66
this._parent = []
77
this._failedCount = 0
8+
9+
this.sentMessages = 0 // number of messages sent to the parent
10+
this.receivedMessages = 0 // number of messages received by the parent
811
}
912

1013
suiteStarted (suite = {}) {
@@ -70,13 +73,27 @@ class JasmineReporter {
7073
}
7174

7275
message.runner[this._cid] = this._capabilities
73-
this.send(message)
76+
this.sentMessages++
77+
this.send(message, null, {}, () => ++this.receivedMessages)
7478
}
7579

7680
send (...args) {
7781
process.send.apply(process, args)
7882
}
7983

84+
/**
85+
* wait until all messages were sent to parent
86+
*/
87+
waitUntilSettled () {
88+
return new Promise((resolve) => {
89+
const interval = setInterval(() => {
90+
if (this.sentMessages !== this.receivedMessages) return
91+
clearInterval(interval)
92+
resolve()
93+
}, 100)
94+
})
95+
}
96+
8097
getFailedCount () {
8198
return this._failedCount
8299
}

test/reporter.spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,28 @@ describe('jasmine reporter', () => {
9797
})
9898
})
9999

100+
it('should wait until all events were sent', () => {
101+
const start = (new Date()).getTime()
102+
103+
reporter.specStarted()
104+
reporter.specDone({
105+
status: 'passed',
106+
description: 'my test',
107+
id: 4
108+
})
109+
110+
setTimeout(() => {
111+
send.args[0][3]()
112+
send.args[1][3]()
113+
send.args[2][3]()
114+
}, 500)
115+
116+
return reporter.waitUntilSettled().then(() => {
117+
const end = (new Date()).getTime();
118+
(end - start).should.be.greaterThan(500)
119+
})
120+
})
121+
100122
describe('provides a fail counter', () => {
101123
it('should have right fail count at the end', () => {
102124
reporter.getFailedCount().should.be.exactly(2)

0 commit comments

Comments
 (0)