tests: close process on Errors (#11351)
This commit is contained in:
parent
9d2b65912b
commit
12569b8f09
@ -14,8 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
import {spawn, execSync} from 'child_process';
|
||||||
|
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
import expect from 'expect';
|
import expect from 'expect';
|
||||||
@ -35,7 +34,6 @@ describe('Fixtures', function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let dumpioData = '';
|
let dumpioData = '';
|
||||||
const {spawn} = await import('child_process');
|
|
||||||
const options = Object.assign({}, defaultBrowserOptions, {
|
const options = Object.assign({}, defaultBrowserOptions, {
|
||||||
pipe: true,
|
pipe: true,
|
||||||
dumpio: true,
|
dumpio: true,
|
||||||
@ -57,7 +55,6 @@ describe('Fixtures', function () {
|
|||||||
const {defaultBrowserOptions, puppeteerPath} = await getTestState();
|
const {defaultBrowserOptions, puppeteerPath} = await getTestState();
|
||||||
|
|
||||||
let dumpioData = '';
|
let dumpioData = '';
|
||||||
const {spawn} = await import('child_process');
|
|
||||||
const options = Object.assign({}, defaultBrowserOptions, {dumpio: true});
|
const options = Object.assign({}, defaultBrowserOptions, {dumpio: true});
|
||||||
const res = spawn('node', [
|
const res = spawn('node', [
|
||||||
path.join(__dirname, '../fixtures', 'dumpio.js'),
|
path.join(__dirname, '../fixtures', 'dumpio.js'),
|
||||||
@ -76,7 +73,6 @@ describe('Fixtures', function () {
|
|||||||
const {defaultBrowserOptions, puppeteerPath, puppeteer} =
|
const {defaultBrowserOptions, puppeteerPath, puppeteer} =
|
||||||
await getTestState();
|
await getTestState();
|
||||||
|
|
||||||
const {spawn, execSync} = await import('child_process');
|
|
||||||
const options = Object.assign({}, defaultBrowserOptions, {
|
const options = Object.assign({}, defaultBrowserOptions, {
|
||||||
// Disable DUMPIO to cleanly read stdout.
|
// Disable DUMPIO to cleanly read stdout.
|
||||||
dumpio: false,
|
dumpio: false,
|
||||||
@ -86,6 +82,19 @@ describe('Fixtures', function () {
|
|||||||
puppeteerPath,
|
puppeteerPath,
|
||||||
JSON.stringify(options),
|
JSON.stringify(options),
|
||||||
]);
|
]);
|
||||||
|
let killed = false;
|
||||||
|
function killProcess() {
|
||||||
|
if (killed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
execSync(`taskkill /pid ${res.pid} /T /F`);
|
||||||
|
} else {
|
||||||
|
process.kill(res.pid!);
|
||||||
|
}
|
||||||
|
killed = true;
|
||||||
|
}
|
||||||
|
try {
|
||||||
let wsEndPointCallback: (value: string) => void;
|
let wsEndPointCallback: (value: string) => void;
|
||||||
const wsEndPointPromise = new Promise<string>(x => {
|
const wsEndPointPromise = new Promise<string>(x => {
|
||||||
wsEndPointCallback = x;
|
wsEndPointCallback = x;
|
||||||
@ -106,11 +115,10 @@ describe('Fixtures', function () {
|
|||||||
res.on('close', resolve);
|
res.on('close', resolve);
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
if (process.platform === 'win32') {
|
killProcess();
|
||||||
execSync(`taskkill /pid ${res.pid} /T /F`);
|
|
||||||
} else {
|
|
||||||
process.kill(res.pid!);
|
|
||||||
}
|
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
|
} finally {
|
||||||
|
killProcess();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user