From 7911b51f398332307f468ee23d38447297d381e8 Mon Sep 17 00:00:00 2001 From: Pepper Pancoast Date: Sun, 15 Feb 2026 14:37:56 -0600 Subject: [PATCH] test_runner: skip branches entirely on ignored lines Fixes: https://github.com/nodejs/node/issues/61586 When a branch is entirely on ignored lines (via c8 ignore comments), it should not appear in the BRDA output at all, rather than appearing with 0 coverage. Modified the branch coverage logic to check if all lines in the branch are ignored before adding to branchReports and incrementing totalBranches. This ensures ignored branches don't pollute coverage reports. --- lib/internal/test_runner/coverage.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/internal/test_runner/coverage.js b/lib/internal/test_runner/coverage.js index 8fa9c872568d1e..cb7351ee797867 100644 --- a/lib/internal/test_runner/coverage.js +++ b/lib/internal/test_runner/coverage.js @@ -193,18 +193,20 @@ class TestCoverage { ObjectAssign(range, mapRangeToLines(range, lines)); if (isBlockCoverage) { - ArrayPrototypePush(branchReports, { - __proto__: null, - line: range.lines[0]?.line, - count: range.count, - }); - - if (range.count !== 0 || - range.ignoredLines === range.lines.length) { - branchesCovered++; + // Skip branches that are entirely on ignored lines + if (range.ignoredLines !== range.lines.length) { + ArrayPrototypePush(branchReports, { + __proto__: null, + line: range.lines[0]?.line, + count: range.count, + }); + + if (range.count !== 0) { + branchesCovered++; + } + + totalBranches++; } - - totalBranches++; } }