nodejs / nodejs/node

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

Offen
#61,586 11 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

stale test_runner
Vorherrschende Sprache
JavaScript
Sterne
122k
Forks
37.3k
Ø Merge
4 T. 2 Std.
Gemergte PRs (30 T.)
283

Beschreibung

Version

v24.13.0

Platform

Darwin 24.6.0 (macOS)

Subsystem

test_runner

What steps will reproduce the bug?
  1. Create a file with a branch and /* node:coverage ignore next */ comment:
// src/example.js
function getValue(condition) {
  if (condition) {
    return 'truthy';
  }
  /* node:coverage ignore next */
  return 'falsy';
}

module.exports = { getValue };
  1. Create a test that only covers the truthy branch:
// test/example.test.js
const { describe, it } = require('node:test');
const assert = require('node:assert');
const { getValue } = require('../src/example.js');

describe('getValue', () => {
  it('should return truthy when condition is true', () => {
    assert.strictEqual(getValue(true), 'truthy');
  });
});
  1. Run with coverage:
node --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test test/example.test.js
  1. Examine the generated lcov.info
How often does it reproduce? Is there a required condition?

Always reproducible.

What is the expected behavior? Why is that the expected behavior?

The /* node:coverage ignore next */ comment should exclude both:

  • The DA (line coverage) entry for the ignored line
  • The BRDA (branch coverage) entry for the branch leading to the ignored code

This is the expected behavior because:

  1. The purpose of ignore comments is to exclude code from coverage calculations
  2. c8 (which also uses V8 coverage) correctly handles this by marking both DA and BRDA as covered for ignored lines
What do you see instead?
  • DA: Line 6 (return 'falsy';) is correctly excluded from the lcov output
  • BRDA: Branch entry remains as uncovered: BRDA:4,2,0,0
BRDA:1,0,0,1
BRDA:1,1,0,1
BRDA:4,2,0,0    <-- This branch should be excluded but remains as uncovered
BRF:3
BRH:2           <-- Only 2 of 3 branches hit (66.67%)
DA:1,1
DA:2,1
DA:3,1
DA:4,1
DA:5,0
DA:7,1          <-- DA:6 is missing (correctly excluded)
...

This causes branch coverage to report 66.67% instead of 100%, which impacts CI/CD pipelines that enforce branch coverage thresholds.

Additional information

Comparison with c8:

Using c8 with /* c8 ignore next */ on the same code structure produces the correct result:

DA:5,1          # Line marked as covered (ignored)
DA:6,1          # Line marked as covered (ignored)
BRDA:5,2,0,1    # Branch marked as covered (ignored)
BRF:3
BRH:3           # All 3 branches "hit" (100%)

Minimal reproduction repository:

https://github.com/tobigumo/node-coverage-brda-bug

git clone https://github.com/tobigumo/node-coverage-brda-bug.git
cd node-coverage-brda-bug
npm install
npm run test
# Compare coverage/lcov-native.info (Node.js native - has bug) with coverage/lcov.info (c8 - correct)

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem Repository für die minimale Reproduktion und führe dessen nativen Coverage-Befehl sowie den c8-Coverage-Befehl aus, um coverage/lcov-native.info mit coverage/lcov.info zu vergleichen. Verfolge die Coverage- und lcov-Behandlung von test_runner für den Ignore-Kommentar in example.js und den Fall test/example.test.js. Fertig ist es, wenn der ignorierte Branch keinen nicht abgedeckten BRDA-Eintrag mehr erzeugt und die Branch-Coverage 100 % meldet.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript
Bereich
testing-qa
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Aktiv
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
68/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.