mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
test: fix "crash cases" tests not failing properly (#37325)
* test: fix "crash cases" tests not failing properly Co-authored-by: Alexey Kuzmin <alex.s.kuzmin@gmail.com> * fixup! test: fix "crash cases" tests not failing properly Co-authored-by: Alexey Kuzmin <alex.s.kuzmin@gmail.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Alexey Kuzmin <alex.s.kuzmin@gmail.com>
This commit is contained in:
@@ -8,7 +8,7 @@ const fixturePath = path.resolve(__dirname, 'fixtures', 'crash-cases');
|
||||
|
||||
let children: cp.ChildProcessWithoutNullStreams[] = [];
|
||||
|
||||
const runFixtureAndEnsureCleanExit = (args: string[]) => {
|
||||
const runFixtureAndEnsureCleanExit = async (args: string[]) => {
|
||||
let out = '';
|
||||
const child = cp.spawn(process.execPath, args);
|
||||
children.push(child);
|
||||
@@ -18,17 +18,20 @@ const runFixtureAndEnsureCleanExit = (args: string[]) => {
|
||||
child.stderr.on('data', (chunk: Buffer) => {
|
||||
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) => {
|
||||
if (code !== 0 || signal !== null) {
|
||||
console.error(out);
|
||||
}
|
||||
expect(signal).to.equal(null, 'exit signal should be null');
|
||||
expect(code).to.equal(0, 'should have exited with code 0');
|
||||
children = children.filter(c => c !== child);
|
||||
resolve();
|
||||
resolve({ code, signal });
|
||||
});
|
||||
});
|
||||
if (code !== 0 || signal !== null) {
|
||||
console.error(out);
|
||||
}
|
||||
children = children.filter(c => c !== child);
|
||||
|
||||
expect(signal).to.equal(null, 'exit signal should be null');
|
||||
expect(code).to.equal(0, 'should have exited with code 0');
|
||||
};
|
||||
|
||||
const shouldRunCase = (crashCase: string) => {
|
||||
|
||||
@@ -62,10 +62,10 @@ describe('modules support', () => {
|
||||
|
||||
ifit(features.isRunAsNodeEnabled())('can be required in node binary', async function () {
|
||||
const child = childProcess.fork(path.join(fixtures, 'module', 'uv-dlopen.js'));
|
||||
await new Promise<void>(resolve => child.once('exit', (exitCode) => {
|
||||
expect(exitCode).to.equal(0);
|
||||
resolve();
|
||||
const exitCode = await new Promise<number | null>(resolve => child.once('exit', (exitCode) => {
|
||||
resolve(exitCode);
|
||||
}));
|
||||
expect(exitCode).to.equal(0);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user