mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
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: https://github.com/nodejs/node/pull/64049 Refs: https://github.com/nodejs/reliability/issues?q=%22test-output-lcov-reporter%22 Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
This commit is contained in:
1 parent
744e40e05e
commit
6fcd3cf516
2 files changed
+32
-2
No files matched your search
@@ -235,13 +235,30 @@ function replaceJunitDuration(str) {
|
||||
// This transform picks only the first line and then the lines from the test
|
||||
// file.
|
||||
function pickTestFileFromLcov(str) {
|
||||
const expectedFile = 'output.js';
|
||||
const lines = str.split(/\n/);
|
||||
const firstLineOfTestFile = lines.findIndex(
|
||||
(line) => line.startsWith('SF:') && line.trim().endsWith('output.js'),
|
||||
(line) => line.startsWith('SF:') && line.trim().endsWith(expectedFile),
|
||||
);
|
||||
|
||||
if (firstLineOfTestFile === -1) {
|
||||
assert.fail(
|
||||
`Could not find LCOV source record ending with ${expectedFile} ` +
|
||||
`in LCOV output:\n${str || '<empty>'}`,
|
||||
);
|
||||
}
|
||||
|
||||
const lastLineOfTestFile = lines.findIndex(
|
||||
(line, index) => index > firstLineOfTestFile && line.trim() === 'end_of_record',
|
||||
);
|
||||
|
||||
if (lastLineOfTestFile === -1) {
|
||||
assert.fail(
|
||||
`Could not find end_of_record for LCOV source record ending with ${expectedFile} ` +
|
||||
`in LCOV output:\n${str}`,
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
lines[0] + '\n' + lines.slice(firstLineOfTestFile, lastLineOfTestFile + 1).join('\n') + '\n'
|
||||
);
|
||||
|
||||
+14
-1
@@ -3,7 +3,7 @@ require('../../../common');
|
||||
const fixtures = require('../../../common/fixtures');
|
||||
const spawn = require('node:child_process').spawn;
|
||||
|
||||
spawn(
|
||||
const child = spawn(
|
||||
process.execPath,
|
||||
[
|
||||
'--no-warnings',
|
||||
@@ -14,3 +14,16 @@ spawn(
|
||||
],
|
||||
{ stdio: 'inherit' },
|
||||
);
|
||||
|
||||
child.on('error', (err) => {
|
||||
throw err;
|
||||
});
|
||||
|
||||
child.on('exit', (code, signal) => {
|
||||
if (signal) {
|
||||
process.kill(process.pid, signal);
|
||||
return;
|
||||
}
|
||||
|
||||
process.exitCode = code ?? 1;
|
||||
});
|
||||
Reference in new issue
Block a user