Skip to content

test_runner: report ignored branches as covered in lcov output#63736

Open
algojogacor wants to merge 1 commit into
nodejs:mainfrom
algojogacor:fix/coverage-ignored-branches-lcov
Open

test_runner: report ignored branches as covered in lcov output#63736
algojogacor wants to merge 1 commit into
nodejs:mainfrom
algojogacor:fix/coverage-ignored-branches-lcov

Conversation

@algojogacor
Copy link
Copy Markdown

This is an independent contribution and is not affiliated with, endorsed by, or related to any hackathon or competition.

Summary

When /* node:coverage ignore next */ is used to exclude a branch return from coverage, the DA (line coverage) entry is correctly excluded from the lcov output but the BRDA (branch coverage) entry remains as uncovered (BRDA:4,2,0,0). This causes branch coverage to report lower than expected.

Root Cause

In lib/internal/test_runner/coverage.js, branch coverage ranges are added to branchReports with the raw V8 count (0 for uncovered branches). While coveredBranchCount correctly handles ignored branches (counting them as covered), the individual branch report still carries count=0, which the lcov reporter outputs as an uncovered branch.

Fix

When a branch range spans entirely ignored lines (range.ignoredLines === range.lines.length), report it with count=1 instead of the raw V8 count. This matches the behavior of c8 and ensures lcov output correctly represents ignored branches as covered.

Testing

Existing coverage tests continue to pass. Manual verification against the reproduction case from the issue confirms:

  • DA entries for ignored lines are excluded (unchanged behavior)
  • BRDA entries for ignored branches now appear as covered (count=1)
  • Branch coverage summary reports 100% as expected

Fixes #61586

@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem. labels Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test_runner: node:coverage ignore comments exclude DA but leave BRDA in lcov output

3 participants