Skip to content

Commit c586567

Browse files
committed
fix: wait for Chrome to exit
1 parent a164da8 commit c586567

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

lib/index.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ module.exports = class ReactBenchmark extends EventEmitter {
2828
})
2929
}
3030

31-
_shutdown() {
32-
this.chrome.stop()
33-
this.server.stop()
31+
async _shutdown() {
32+
await this.chrome.stop()
33+
await this.server.stop()
3434
this.running = false
3535
}
3636

@@ -61,19 +61,17 @@ module.exports = class ReactBenchmark extends EventEmitter {
6161
const port = await this.server.start(outputPath)
6262

6363
return new Promise((resolve, reject) => {
64-
this.chrome.once('complete', (benchmark) => {
64+
this.chrome.once('complete', async (benchmark) => {
6565
if (!devtools) {
66-
this._shutdown()
66+
await this._shutdown()
6767
}
68-
6968
resolve(benchmark)
7069
})
7170

72-
this.chrome.once('error', (err) => {
71+
this.chrome.once('error', async (err) => {
7372
if (!devtools) {
74-
this._shutdown()
73+
await this._shutdown()
7574
}
76-
7775
reject(err)
7876
})
7977

test/cli.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ const path = require('path')
22
const test = require('ava')
33
const execa = require('execa')
44

5-
const sleep = (ms) => new Promise((res) => setTimeout(res, ms))
6-
75
test('runs benchmark', async (t) => {
86
const binPath = path.resolve(__dirname, '../lib/cli.js')
97
const fixturePath = path.resolve(__dirname, 'fixtures/benchmark.js')
@@ -23,7 +21,6 @@ test('throttles CPU', async (t) => {
2321
const fixturePath = path.resolve(__dirname, 'fixtures/benchmark.js')
2422

2523
const woutT = (await execa(binPath, [fixturePath])).stdout
26-
await sleep(100) // sometimes port is still in use
2724
const withT = (await execa(binPath, [fixturePath, '--cpuThrottle=4'])).stdout
2825

2926
// difference should be more then 2 times

0 commit comments

Comments
 (0)