2020-05-08 18:30:37 +00:00
|
|
|
import { expect } from 'chai';
|
2024-10-03 02:10:44 +00:00
|
|
|
|
2023-06-15 14:42:27 +00:00
|
|
|
import * as cp from 'node:child_process';
|
|
|
|
import * as fs from 'node:fs';
|
|
|
|
import * as path from 'node:path';
|
2024-10-03 02:10:44 +00:00
|
|
|
|
2024-10-25 15:32:00 +00:00
|
|
|
import { ifit, waitUntil } from './lib/spec-helpers';
|
2020-05-08 18:17:28 +00:00
|
|
|
|
2020-05-08 18:30:37 +00:00
|
|
|
const fixturePath = path.resolve(__dirname, 'fixtures', 'crash-cases');
|
2020-05-08 18:17:28 +00:00
|
|
|
|
2020-05-08 18:30:37 +00:00
|
|
|
let children: cp.ChildProcessWithoutNullStreams[] = [];
|
2020-05-08 18:17:28 +00:00
|
|
|
|
2023-02-17 09:14:00 +00:00
|
|
|
const runFixtureAndEnsureCleanExit = async (args: string[]) => {
|
2020-05-08 18:30:37 +00:00
|
|
|
let out = '';
|
|
|
|
const child = cp.spawn(process.execPath, args);
|
|
|
|
children.push(child);
|
2020-05-08 18:17:28 +00:00
|
|
|
child.stdout.on('data', (chunk: Buffer) => {
|
2020-05-08 18:30:37 +00:00
|
|
|
out += chunk.toString();
|
|
|
|
});
|
2020-05-08 18:17:28 +00:00
|
|
|
child.stderr.on('data', (chunk: Buffer) => {
|
2020-05-08 18:30:37 +00:00
|
|
|
out += chunk.toString();
|
|
|
|
});
|
2023-02-17 09:14:00 +00:00
|
|
|
|
|
|
|
type CodeAndSignal = {code: number | null, signal: NodeJS.Signals | null};
|
|
|
|
const { code, signal } = await new Promise<CodeAndSignal>((resolve) => {
|
2020-05-08 18:17:28 +00:00
|
|
|
child.on('exit', (code, signal) => {
|
2023-02-17 09:14:00 +00:00
|
|
|
resolve({ code, signal });
|
2020-05-08 18:30:37 +00:00
|
|
|
});
|
|
|
|
});
|
2023-02-17 09:14:00 +00:00
|
|
|
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');
|
2020-05-08 18:30:37 +00:00
|
|
|
};
|
2020-05-08 18:17:28 +00:00
|
|
|
|
2022-10-20 22:06:06 +00:00
|
|
|
const shouldRunCase = (crashCase: string) => {
|
|
|
|
switch (crashCase) {
|
|
|
|
// TODO(jkleinsc) fix this flaky test on Windows 32-bit
|
|
|
|
case 'quit-on-crashed-event': {
|
|
|
|
return (process.platform !== 'win32' || process.arch !== 'ia32');
|
|
|
|
}
|
2024-03-08 00:17:39 +00:00
|
|
|
// TODO(jkleinsc) fix this test on Linux on arm/arm64 and 32bit windows
|
2022-10-20 22:06:06 +00:00
|
|
|
case 'js-execute-iframe': {
|
2024-03-08 00:17:39 +00:00
|
|
|
if (process.platform === 'win32') {
|
|
|
|
return process.arch !== 'ia32';
|
|
|
|
} else {
|
|
|
|
return (process.platform !== 'linux' || (process.arch !== 'arm64' && process.arch !== 'arm'));
|
|
|
|
}
|
2022-10-20 22:06:06 +00:00
|
|
|
}
|
|
|
|
default: {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-04-09 07:09:17 +00:00
|
|
|
describe('crash cases', () => {
|
2024-10-25 15:32:00 +00:00
|
|
|
afterEach(async () => {
|
2020-05-08 18:17:28 +00:00
|
|
|
for (const child of children) {
|
2020-05-08 18:30:37 +00:00
|
|
|
child.kill();
|
2020-05-08 18:17:28 +00:00
|
|
|
}
|
2024-10-25 15:32:00 +00:00
|
|
|
await waitUntil(() => (children.length === 0));
|
2020-05-08 18:30:37 +00:00
|
|
|
children.length = 0;
|
|
|
|
});
|
|
|
|
const cases = fs.readdirSync(fixturePath);
|
2020-05-08 18:17:28 +00:00
|
|
|
|
|
|
|
for (const crashCase of cases) {
|
2022-10-20 22:06:06 +00:00
|
|
|
ifit(shouldRunCase(crashCase))(`the "${crashCase}" case should not crash`, () => {
|
2020-05-08 18:30:37 +00:00
|
|
|
const fixture = path.resolve(fixturePath, crashCase);
|
|
|
|
const argsFile = path.resolve(fixture, 'electron.args');
|
|
|
|
const args = [fixture];
|
2020-05-08 18:17:28 +00:00
|
|
|
if (fs.existsSync(argsFile)) {
|
2020-05-08 18:30:37 +00:00
|
|
|
args.push(...fs.readFileSync(argsFile, 'utf8').trim().split('\n'));
|
2020-05-08 18:17:28 +00:00
|
|
|
}
|
2020-05-08 18:30:37 +00:00
|
|
|
return runFixtureAndEnsureCleanExit(args);
|
|
|
|
});
|
2020-05-08 18:17:28 +00:00
|
|
|
}
|
2020-05-08 18:30:37 +00:00
|
|
|
});
|