From ff9122c20c84f0c33df5065bae4511ea473f5672 Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Mon, 29 Jun 2026 00:04:35 -0700 Subject: [PATCH] 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 --- test/common/assertSnapshot.js | 19 ++++++++++++++++++- .../test-runner/output/lcov_reporter.js | 15 ++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/test/common/assertSnapshot.js b/test/common/assertSnapshot.js index 4fdd0be0ee3..c363ded73ef 100644 --- a/test/common/assertSnapshot.js +++ b/test/common/assertSnapshot.js @@ -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 || ''}`, + ); + } + 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' ); diff --git a/test/fixtures/test-runner/output/lcov_reporter.js b/test/fixtures/test-runner/output/lcov_reporter.js index 832b5d22479..97919cb5c4c 100644 --- a/test/fixtures/test-runner/output/lcov_reporter.js +++ b/test/fixtures/test-runner/output/lcov_reporter.js @@ -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; +});