Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion test/common/assertSnapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,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'
);
Expand Down
15 changes: 14 additions & 1 deletion test/fixtures/test-runner/output/lcov_reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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;
});
Loading