From 8d68d9d2091633425c9058ac9e866b47b8f92a8e Mon Sep 17 00:00:00 2001 From: Jivin Sardine Date: Thu, 26 Mar 2026 13:37:02 +0530 Subject: [PATCH] test_runner: exclude BRDA entries for ignored lines in lcov output When a line is marked with node:coverage ignore next, both the DA (line coverage) entry and the BRDA (branch coverage) entry for branches leading to that line should be excluded from the lcov output. This matches the behavior of c8 and ensures that branch coverage percentages are not artificially reduced by ignored code. Fixes: https://github.com/nodejs/node/issues/61586 --- lib/internal/test_runner/coverage.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/internal/test_runner/coverage.js b/lib/internal/test_runner/coverage.js index 8fa9c872568d1e..9a638c82325c22 100644 --- a/lib/internal/test_runner/coverage.js +++ b/lib/internal/test_runner/coverage.js @@ -193,11 +193,16 @@ class TestCoverage { ObjectAssign(range, mapRangeToLines(range, lines)); if (isBlockCoverage) { - ArrayPrototypePush(branchReports, { - __proto__: null, - line: range.lines[0]?.line, - count: range.count, - }); + // If all lines in the branch are ignored, do not include this + // branch in the coverage report (similar to how ignored lines + // are excluded from DA entries in lcov output). + if (range.ignoredLines !== range.lines.length) { + ArrayPrototypePush(branchReports, { + __proto__: null, + line: range.lines[0]?.line, + count: range.count, + }); + } if (range.count !== 0 || range.ignoredLines === range.lines.length) {