diff --git a/lib/internal/test_runner/coverage.js b/lib/internal/test_runner/coverage.js index 798e41f0ac4be6..e47644ef3381e2 100644 --- a/lib/internal/test_runner/coverage.js +++ b/lib/internal/test_runner/coverage.js @@ -263,14 +263,18 @@ class TestCoverage { ObjectAssign(range, mapRangeToLines(range, lines)); if (isBlockCoverage) { + // If all lines in this range are ignored, report the branch as + // covered (count=1) instead of its actual V8 count. This matches + // the behavior of c8 and ensures the lcov output does not contain + // uncovered BRDA entries for ignored branches. + const count = range.ignoredLines === range.lines.length ? 1 : range.count; ArrayPrototypePush(branchReports, { __proto__: null, line: range.lines[0]?.line, - count: range.count, + count, }); - if (range.count !== 0 || - range.ignoredLines === range.lines.length) { + if (count !== 0) { branchesCovered++; }