Skip to content

test_runner: exclude BRDA entries for ignored lines in LCOV reporter#1

Open
sfgrdsgdsfdrfyg-code wants to merge 1 commit intomainfrom
fix/coverage-ignore-brda
Open

test_runner: exclude BRDA entries for ignored lines in LCOV reporter#1
sfgrdsgdsfdrfyg-code wants to merge 1 commit intomainfrom
fix/coverage-ignore-brda

Conversation

@sfgrdsgdsfdrfyg-code
Copy link
Copy Markdown
Owner

Description

When a line is marked with /* node:coverage ignore next */, the DA (line coverage) entry for that line is correctly excluded from the LCOV output. However, the corresponding BRDA (branch coverage) entry was still being emitted, causing branch coverage to report uncovered branches for code that should be ignored.

This results in incorrect branch coverage percentages (e.g., 66.67% instead of 100%) and impacts CI/CD pipelines that enforce branch coverage thresholds.

Fix

Build a set of ignored line numbers from file.lines (which includes the ignore flag) and skip BRDA entries for those lines.

Testing

The issue includes a minimal reproduction at https://github.com/tobigumo/node-coverage-brda-bug

Steps to reproduce:

  1. Create a file with a branch and /* node:coverage ignore next */ comment on the fallback branch
  2. Create a test that only covers the truthy branch
  3. Run with coverage: node --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test test/example.test.js
  4. Observe that BRDA:4,2,0,0 remains in lcov.info (the bug)
  5. With this fix, the BRDA entry for ignored lines is excluded

Comparison with c8

Using c8 with /* c8 ignore next */ on the same code structure correctly marks both DA and BRDA as covered for ignored lines. This fix aligns Node.js native coverage with c8 behavior.

Closes nodejs#61586

When a line is marked with /* node:coverage ignore next */, the DA entry
for that line is correctly excluded from the LCOV output. However, the
corresponding BRDA entry was still being emitted, causing branch coverage
to report incorrect percentages when using the lcov reporter.

This commit adds:
- A new test fixture (brda_ignore_output.js) with a branch that has
  /* node:coverage ignore next */ to test the BRDA exclusion behavior
- A new test runner (lcov_reporter_brda_ignore.js) for the fixture
- A separate snapshot test case for this specific scenario
- Updates to lcov.js to filter BRDA entries for ignored lines

PR-URL: nodejs#62740
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

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

1 participant