From 0209302d8492520fe61a92cafa4e042b046a267a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 27 Jan 2020 10:29:50 +0900 Subject: [PATCH] test: use exit event to wait for process exit (#21865) --- spec-main/api-app-spec.ts | 6 +++--- spec-main/api-browser-view-spec.ts | 2 +- spec-main/api-crash-reporter-spec.ts | 2 +- spec-main/api-menu-spec.ts | 4 ++-- spec-main/api-net-log-spec.ts | 2 +- spec-main/api-session-spec.ts | 2 +- spec-main/api-web-contents-view-spec.ts | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/spec-main/api-app-spec.ts b/spec-main/api-app-spec.ts index 53af7a2c0b2a..5fdb9a33871d 100644 --- a/spec-main/api-app-spec.ts +++ b/spec-main/api-app-spec.ts @@ -160,7 +160,7 @@ describe('app module', () => { if (appProcess && appProcess.stdout) { appProcess.stdout.on('data', data => { output += data }) } - const [code] = await emittedOnce(appProcess, 'close') + const [code] = await emittedOnce(appProcess, 'exit') if (process.platform !== 'win32') { expect(output).to.include('Exit event with code: 123') @@ -173,7 +173,7 @@ describe('app module', () => { const electronPath = process.execPath appProcess = cp.spawn(electronPath, [appPath]) - const [code, signal] = await emittedOnce(appProcess, 'close') + const [code, signal] = await emittedOnce(appProcess, 'exit') expect(signal).to.equal(null, 'exit signal should be null, if you see this please tag @MarshallOfSound') expect(code).to.equal(123, 'exit code should be 123, if you see this please tag @MarshallOfSound') @@ -194,7 +194,7 @@ describe('app module', () => { if (appProcess && appProcess.stdout) { appProcess.stdout.on('data', () => appProcess!.kill()) } - const [code, signal] = await emittedOnce(appProcess, 'close') + const [code, signal] = await emittedOnce(appProcess, 'exit') const message = `code:\n${code}\nsignal:\n${signal}` expect(code).to.equal(0, message) diff --git a/spec-main/api-browser-view-spec.ts b/spec-main/api-browser-view-spec.ts index 50588b8725a0..3c36a1c9ebb5 100644 --- a/spec-main/api-browser-view-spec.ts +++ b/spec-main/api-browser-view-spec.ts @@ -227,7 +227,7 @@ describe('BrowserView module', () => { const appPath = path.join(__dirname, 'fixtures', 'api', 'leak-exit-browserview.js') const electronPath = process.execPath const appProcess = ChildProcess.spawn(electronPath, [appPath]) - const [code] = await emittedOnce(appProcess, 'close') + const [code] = await emittedOnce(appProcess, 'exit') expect(code).to.equal(0) }) }) diff --git a/spec-main/api-crash-reporter-spec.ts b/spec-main/api-crash-reporter-spec.ts index abf87cfc8e09..588e36f693df 100644 --- a/spec-main/api-crash-reporter-spec.ts +++ b/spec-main/api-crash-reporter-spec.ts @@ -340,7 +340,7 @@ ifdescribe(!process.mas && !process.env.DISABLE_CRASH_REPORTER_TESTS && process. it('does not prevent process from crashing', (done) => { const appPath = path.join(fixtures, 'api', 'cookie-app') const appProcess = childProcess.spawn(process.execPath, [appPath]) - appProcess.once('close', () => { + appProcess.once('exit', () => { done() }) }) diff --git a/spec-main/api-menu-spec.ts b/spec-main/api-menu-spec.ts index 73e938165723..241c5719e6b3 100644 --- a/spec-main/api-menu-spec.ts +++ b/spec-main/api-menu-spec.ts @@ -878,7 +878,7 @@ describe('Menu module', function () { let output = '' appProcess.stdout.on('data', data => { output += data }) - await emittedOnce(appProcess, 'close') + await emittedOnce(appProcess, 'exit') expect(output).to.include('Window has no menu') }) @@ -889,7 +889,7 @@ describe('Menu module', function () { let output = '' appProcess.stdout.on('data', data => { output += data }) - await emittedOnce(appProcess, 'close') + await emittedOnce(appProcess, 'exit') expect(output).to.include('Window has no menu') }) }) diff --git a/spec-main/api-net-log-spec.ts b/spec-main/api-net-log-spec.ts index 20d1aa4bd343..1db275504dab 100644 --- a/spec-main/api-net-log-spec.ts +++ b/spec-main/api-net-log-spec.ts @@ -161,7 +161,7 @@ describe('netLog module', () => { } }) - await emittedOnce(appProcess, 'close') + await emittedOnce(appProcess, 'exit') expect(fs.existsSync(dumpFileDynamic)).to.be.true('dynamic dump file exists') }) }) diff --git a/spec-main/api-session-spec.ts b/spec-main/api-session-spec.ts index 58a38bef0b3c..4969cecba510 100644 --- a/spec-main/api-session-spec.ts +++ b/spec-main/api-session-spec.ts @@ -234,7 +234,7 @@ describe('session module', () => { ) appProcess.stdout.on('data', data => { output += data }) - appProcess.stdout.on('end', () => { + appProcess.on('exit', () => { resolve(output.replace(/(\r\n|\n|\r)/gm, '')) }) }) diff --git a/spec-main/api-web-contents-view-spec.ts b/spec-main/api-web-contents-view-spec.ts index 78657a4d1186..1e2fda543bc0 100644 --- a/spec-main/api-web-contents-view-spec.ts +++ b/spec-main/api-web-contents-view-spec.ts @@ -30,7 +30,7 @@ describe('WebContentsView', () => { const appPath = path.join(__dirname, 'fixtures', 'api', 'leak-exit-webcontentsview.js') const electronPath = process.execPath const appProcess = ChildProcess.spawn(electronPath, [appPath]) - const [code] = await emittedOnce(appProcess, 'close') + const [code] = await emittedOnce(appProcess, 'exit') expect(code).to.equal(0) }) })