Skip to content

Commit 95bf502

Browse files
committed
fix(test): preserve shard crash exit codes and failure reports
1 parent 9aa82b1 commit 95bf502

3 files changed

Lines changed: 46 additions & 7 deletions

File tree

‎scripts/test-projects.mts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ function runPnpmSpecCommand(spec: VitestRunSpec, pnpmArgs: string[], workerRun?:
117117

118118
completion.then(
119119
({ code, signal }) => {
120-
const forwardedSignal = getForwardedSignal();
121-
if (forwardedSignal) {
122-
resolve({ code: 143, noOutputTimedOut, signal: forwardedSignal });
123-
return;
124-
}
125-
resolve({ code: code ?? (signal ? 143 : 1), noOutputTimedOut, signal });
120+
const exitSignal = getForwardedSignal() ?? signal;
121+
resolve({
122+
code: exitSignal ? signalExitCode(exitSignal) : (code ?? 1),
123+
noOutputTimedOut,
124+
signal: exitSignal,
125+
});
126126
},
127127
(error: unknown) => {
128128
reject(error instanceof Error ? error : new Error(String(error)));

‎test/scripts/vitest-report-fixture.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,12 @@ export function createVitestReportFixture(root: string, evidence = path.join(roo
8787

8888
return async (
8989
mode: ReportFixtureMode,
90-
options: { nativeArgs?: string[]; entry?: "projects" | "batch-cli"; report?: boolean } = {},
90+
options: {
91+
nativeArgs?: string[];
92+
entry?: "projects" | "batch-cli";
93+
report?: boolean;
94+
crashSignal?: "SIGABRT" | "SIGKILL";
95+
} = {},
9196
) => {
9297
const deadline = performance.now() + 45000;
9398
const output = path.join(evidence, "result.json");
@@ -99,6 +104,7 @@ export function createVitestReportFixture(root: string, evidence = path.join(roo
99104
const prelude = `import fs from 'node:fs';
100105
${mode === "teardown-timeout" && index === 0 ? "setInterval(()=>{},1000);" : ""}
101106
const merging = process.argv.includes('--mergeReports');
107+
${options.crashSignal && index === 0 ? `if(!merging){process.kill(process.pid,${JSON.stringify(options.crashSignal)});await new Promise(()=>setInterval(()=>{},1000));}` : ""}
102108
const output = process.argv.find(arg => arg.startsWith('--outputFile.json='))?.slice('--outputFile.json='.length);
103109
${mode === "coverage-missing" && index === 0 ? `if(!merging)process.once('exit',()=>{const dir=process.argv.find(arg=>arg.startsWith('--coverage.reportsDirectory='))?.split('=').slice(1).join('=');if(dir&&fs.existsSync(dir+'/lcov.info')){fs.copyFileSync(dir+'/lcov.info',dir+'/lcov.info.native-original');fs.unlinkSync(dir+'/lcov.info');}});` : ""}
104110
${mode === "merge-failure" ? `if(merging)throw new Error('owned native merge failure');` : ""}

‎test/scripts/vitest-report-owner.test.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,39 @@ describe.skipIf(process.platform === "win32")("native multi-invocation report ow
2424
const dirs = useAutoCleanupTempDirTracker(afterEach);
2525
const run = (mode: ReportFixtureMode) => createVitestReportFixture(dirs.make("oc-report-"))(mode);
2626

27+
it.each([
28+
["serial", "projects", false, "SIGABRT", 134],
29+
["parallel", "projects", false, "SIGABRT", 134],
30+
["serial", undefined, false, "SIGABRT", 134],
31+
["parallel", undefined, false, "SIGABRT", 134],
32+
["serial", "projects", true, "SIGABRT", 134],
33+
["parallel", "projects", true, "SIGABRT", 134],
34+
["parallel", "projects", true, "SIGKILL", 137],
35+
] as const)(
36+
"preserves shard crashes: %s entry=%s report=%s signal=%s",
37+
{ timeout: 60000 },
38+
async (mode, entry, report, crashSignal, exitCode) => {
39+
const result = await createVitestReportFixture(dirs.make("oc-report-crash-"))(mode, {
40+
entry,
41+
report,
42+
crashSignal,
43+
});
44+
expect(result.code !== 0 || result.signal !== null, result.stderr).toBe(true);
45+
expect(result.signal === crashSignal || result.code === exitCode, result.stderr).toBe(true);
46+
expect(result.stderr).not.toMatch(/\[test\] passed /u);
47+
expect(result.stderr.trimEnd().split("\n").at(-1)).toBe(`[test] FAILED (exit ${exitCode})`);
48+
if (report) {
49+
const index = json(path.join(result.reportSet!, "index.json"));
50+
expect(index.complete).toBe(false);
51+
expect(index.entries[0].attempts[0].outcome).toMatchObject({
52+
code: exitCode,
53+
signal: crashSignal,
54+
});
55+
expect(fs.existsSync(result.output)).toBe(false);
56+
}
57+
},
58+
);
59+
2760
it.each([
2861
"serial",
2962
"parallel",

0 commit comments

Comments
 (0)