Skip to content

Commit a7f3aed

Browse files
author
Code Clawd
committed
test_runner: exclude BRDA entries for ignored lines in LCOV reporter
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. PR-URL: #62740
1 parent d0fa608 commit a7f3aed

File tree

1 file changed

+15
-1
lines changed
  • lib/internal/test_runner/reporter

1 file changed

+15
-1
lines changed

lib/internal/test_runner/reporter/lcov.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const { relative } = require('path');
44
const Transform = require('internal/streams/transform');
5+
const { SafeSet } = require('internal/primordials');
56

67
// This reporter is based on the LCOV format, as described here:
78
// https://ltp.sourceforge.net/coverage/lcov/geninfo.1.php
@@ -68,7 +69,20 @@ class LcovReporter extends Transform {
6869
// Taken is either '-' if the basic block containing the branch was
6970
// never executed or a number indicating how often that branch was
7071
// taken.
72+
// Build set of ignored line numbers from coverage data.
73+
// A line is ignored if it appears with ignore=true in the file.lines array.
74+
const ignoredLineSet = new SafeSet();
75+
for (let k = 0; k < file.lines.length; k++) {
76+
if (file.lines[k].ignore) {
77+
ignoredLineSet.add(file.lines[k].line);
78+
}
79+
}
80+
7181
for (let j = 0; j < file.branches.length; j++) {
82+
// Skip branches that point to ignored lines.
83+
if (ignoredLineSet.has(file.branches[j].line)) {
84+
continue;
85+
}
7286
lcov += `BRDA:${file.branches[j].line},${j},0,${file.branches[j].count}\n`;
7387
}
7488

@@ -104,4 +118,4 @@ class LcovReporter extends Transform {
104118
}
105119
}
106120

107-
module.exports = LcovReporter;
121+
module.exports = LcovReporter;

0 commit comments

Comments
 (0)