From ec5434914f0657aa97dd2cc741f1f9183abc5c03 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Sun, 21 Jun 2026 13:21:50 -0700 Subject: [PATCH 1/2] 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 --- test/common/assertSnapshot.js | 16 ++++++++++++++++ .../fixtures/test-runner/output/lcov_reporter.js | 15 ++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/test/common/assertSnapshot.js b/test/common/assertSnapshot.js index 9a7482020e098a..8ea40d4887f998 100644 --- a/test/common/assertSnapshot.js +++ b/test/common/assertSnapshot.js @@ -238,9 +238,25 @@ function pickTestFileFromLcov(str) { const firstLineOfTestFile = lines.findIndex( (line) => line.startsWith('SF:') && line.trim().endsWith('output.js'), ); + + if (firstLineOfTestFile === -1) { + assert.fail( + 'Could not find coverage for test/fixtures/test-runner/output/output.js ' + + `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 test/fixtures/test-runner/output/output.js ' + + `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 832b5d2247965c..97919cb5c4c81f 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; +}); From 2f1b5611652545c69ec1f49e27ae0d99b17dfcdb Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Sun, 21 Jun 2026 13:30:15 -0700 Subject: [PATCH 2/2] test: avoid hardcoded path in lcov diagnostic --- test/common/assertSnapshot.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/common/assertSnapshot.js b/test/common/assertSnapshot.js index 8ea40d4887f998..d1ec30bfb78c6a 100644 --- a/test/common/assertSnapshot.js +++ b/test/common/assertSnapshot.js @@ -234,14 +234,15 @@ 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 coverage for test/fixtures/test-runner/output/output.js ' + + `Could not find LCOV source record ending with ${expectedFile} ` + `in LCOV output:\n${str || ''}`, ); } @@ -252,7 +253,7 @@ function pickTestFileFromLcov(str) { if (lastLineOfTestFile === -1) { assert.fail( - 'Could not find end_of_record for test/fixtures/test-runner/output/output.js ' + + `Could not find end_of_record for LCOV source record ending with ${expectedFile} ` + `in LCOV output:\n${str}`, ); }