Skip to content

Commit ff9122c

Browse files
trivikrrichardlau
authored andcommitted
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 PR-URL: #64049 Refs: https://github.com/nodejs/reliability/issues?q=%22test-output-lcov-reporter%22 Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
1 parent f3db304 commit ff9122c

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

test/common/assertSnapshot.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,30 @@ function replaceJunitDuration(str) {
235235
// This transform picks only the first line and then the lines from the test
236236
// file.
237237
function pickTestFileFromLcov(str) {
238+
const expectedFile = 'output.js';
238239
const lines = str.split(/\n/);
239240
const firstLineOfTestFile = lines.findIndex(
240-
(line) => line.startsWith('SF:') && line.trim().endsWith('output.js'),
241+
(line) => line.startsWith('SF:') && line.trim().endsWith(expectedFile),
241242
);
243+
244+
if (firstLineOfTestFile === -1) {
245+
assert.fail(
246+
`Could not find LCOV source record ending with ${expectedFile} ` +
247+
`in LCOV output:\n${str || '<empty>'}`,
248+
);
249+
}
250+
242251
const lastLineOfTestFile = lines.findIndex(
243252
(line, index) => index > firstLineOfTestFile && line.trim() === 'end_of_record',
244253
);
254+
255+
if (lastLineOfTestFile === -1) {
256+
assert.fail(
257+
`Could not find end_of_record for LCOV source record ending with ${expectedFile} ` +
258+
`in LCOV output:\n${str}`,
259+
);
260+
}
261+
245262
return (
246263
lines[0] + '\n' + lines.slice(firstLineOfTestFile, lastLineOfTestFile + 1).join('\n') + '\n'
247264
);

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)