Skip to content

Commit ec54349

Browse files
committed
test: improve lcov reporter snapshot diagnostics
Propagate failures from the nested LCOV reporter fixture process and make missing LCOV records fail with a targeted assertion instead of comparing against blank transformed output. Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: openai:gpt-5.5
1 parent 2e19033 commit ec54349

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

test/common/assertSnapshot.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,25 @@ function pickTestFileFromLcov(str) {
238238
const firstLineOfTestFile = lines.findIndex(
239239
(line) => line.startsWith('SF:') && line.trim().endsWith('output.js'),
240240
);
241+
242+
if (firstLineOfTestFile === -1) {
243+
assert.fail(
244+
'Could not find coverage for test/fixtures/test-runner/output/output.js ' +
245+
`in LCOV output:\n${str || '<empty>'}`,
246+
);
247+
}
248+
241249
const lastLineOfTestFile = lines.findIndex(
242250
(line, index) => index > firstLineOfTestFile && line.trim() === 'end_of_record',
243251
);
252+
253+
if (lastLineOfTestFile === -1) {
254+
assert.fail(
255+
'Could not find end_of_record for test/fixtures/test-runner/output/output.js ' +
256+
`in LCOV output:\n${str}`,
257+
);
258+
}
259+
244260
return (
245261
lines[0] + '\n' + lines.slice(firstLineOfTestFile, lastLineOfTestFile + 1).join('\n') + '\n'
246262
);

test/fixtures/test-runner/output/lcov_reporter.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ require('../../../common');
33
const fixtures = require('../../../common/fixtures');
44
const spawn = require('node:child_process').spawn;
55

6-
spawn(
6+
const child = spawn(
77
process.execPath,
88
[
99
'--no-warnings',
@@ -14,3 +14,16 @@ spawn(
1414
],
1515
{ stdio: 'inherit' },
1616
);
17+
18+
child.on('error', (err) => {
19+
throw err;
20+
});
21+
22+
child.on('exit', (code, signal) => {
23+
if (signal) {
24+
process.kill(process.pid, signal);
25+
return;
26+
}
27+
28+
process.exitCode = code ?? 1;
29+
});

0 commit comments

Comments
 (0)