test: fix "crash cases" tests not failing properly (#37304)
* test: fix "crash cases" tests not failing properly * fixup! test: fix "crash cases" tests not failing properly
This commit is contained in:
parent
ea848bc1c5
commit
73b7aac6a4
2 changed files with 15 additions and 12 deletions
|
@ -8,7 +8,7 @@ const fixturePath = path.resolve(__dirname, 'fixtures', 'crash-cases');
|
||||||
|
|
||||||
let children: cp.ChildProcessWithoutNullStreams[] = [];
|
let children: cp.ChildProcessWithoutNullStreams[] = [];
|
||||||
|
|
||||||
const runFixtureAndEnsureCleanExit = (args: string[]) => {
|
const runFixtureAndEnsureCleanExit = async (args: string[]) => {
|
||||||
let out = '';
|
let out = '';
|
||||||
const child = cp.spawn(process.execPath, args);
|
const child = cp.spawn(process.execPath, args);
|
||||||
children.push(child);
|
children.push(child);
|
||||||
|
@ -18,17 +18,20 @@ const runFixtureAndEnsureCleanExit = (args: string[]) => {
|
||||||
child.stderr.on('data', (chunk: Buffer) => {
|
child.stderr.on('data', (chunk: Buffer) => {
|
||||||
out += chunk.toString();
|
out += chunk.toString();
|
||||||
});
|
});
|
||||||
return new Promise<void>((resolve) => {
|
|
||||||
|
type CodeAndSignal = {code: number | null, signal: NodeJS.Signals | null};
|
||||||
|
const { code, signal } = await new Promise<CodeAndSignal>((resolve) => {
|
||||||
child.on('exit', (code, signal) => {
|
child.on('exit', (code, signal) => {
|
||||||
|
resolve({ code, signal });
|
||||||
|
});
|
||||||
|
});
|
||||||
if (code !== 0 || signal !== null) {
|
if (code !== 0 || signal !== null) {
|
||||||
console.error(out);
|
console.error(out);
|
||||||
}
|
}
|
||||||
|
children = children.filter(c => c !== child);
|
||||||
|
|
||||||
expect(signal).to.equal(null, 'exit signal should be null');
|
expect(signal).to.equal(null, 'exit signal should be null');
|
||||||
expect(code).to.equal(0, 'should have exited with code 0');
|
expect(code).to.equal(0, 'should have exited with code 0');
|
||||||
children = children.filter(c => c !== child);
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const shouldRunCase = (crashCase: string) => {
|
const shouldRunCase = (crashCase: string) => {
|
||||||
|
|
|
@ -62,10 +62,10 @@ describe('modules support', () => {
|
||||||
|
|
||||||
ifit(features.isRunAsNodeEnabled())('can be required in node binary', async function () {
|
ifit(features.isRunAsNodeEnabled())('can be required in node binary', async function () {
|
||||||
const child = childProcess.fork(path.join(fixtures, 'module', 'uv-dlopen.js'));
|
const child = childProcess.fork(path.join(fixtures, 'module', 'uv-dlopen.js'));
|
||||||
await new Promise<void>(resolve => child.once('exit', (exitCode) => {
|
const exitCode = await new Promise<number | null>(resolve => child.once('exit', (exitCode) => {
|
||||||
expect(exitCode).to.equal(0);
|
resolve(exitCode);
|
||||||
resolve();
|
|
||||||
}));
|
}));
|
||||||
|
expect(exitCode).to.equal(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue