From f79d7aff3acdee83bdf8fa2abafd54204dacea87 Mon Sep 17 00:00:00 2001 From: kszongic Date: Sun, 22 Mar 2026 12:27:24 +0000 Subject: [PATCH] test_runner: exclude ignored branches from BRDA in lcov output When using node:coverage ignore comments, line coverage (DA entries) is correctly excluded from the lcov output, but branch coverage (BRDA entries) for branches pointing to ignored lines still appears as uncovered. This causes branch coverage percentages to be incorrectly low. Skip branches entirely when all their lines are ignored by coverage comments, consistent with how ignored lines are already excluded from line reports. Fixes: https://github.com/nodejs/node/issues/61586 --- lib/internal/test_runner/coverage.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/internal/test_runner/coverage.js b/lib/internal/test_runner/coverage.js index 8fa9c872568d1e..7892e67c99887c 100644 --- a/lib/internal/test_runner/coverage.js +++ b/lib/internal/test_runner/coverage.js @@ -193,14 +193,20 @@ class TestCoverage { ObjectAssign(range, mapRangeToLines(range, lines)); if (isBlockCoverage) { + // Skip branches where all lines are ignored by coverage + // comments. This is consistent with how ignored lines are + // excluded from line reports (DA entries in lcov). + if (range.ignoredLines === range.lines.length) { + continue; + } + ArrayPrototypePush(branchReports, { __proto__: null, line: range.lines[0]?.line, count: range.count, }); - if (range.count !== 0 || - range.ignoredLines === range.lines.length) { + if (range.count !== 0) { branchesCovered++; }