Skip to content

Commit aa9d3db

Browse files
committed
fixup! test_runner: exclude ignored lines from BRDA in lcov output
Address review nits: improve code formatting
1 parent 1ae08ae commit aa9d3db

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

lib/internal/test_runner/coverage.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ class TestCoverage {
201201
// If the branch is uncovered but contains ignored lines, treat it as
202202
// covered. This matches the behavior of tools like c8 and ensures that
203203
// ignored code doesn't penalize branch coverage.
204-
const branchCount = (range.count === 0 && range.ignoredLines > 0) ?
205-
1 : range.count;
204+
const branchCount = (range.count === 0 && range.ignoredLines > 0) ? 1 : range.count;
206205

207206
ArrayPrototypePush(branchReports, {
208207
__proto__: null,

test/parallel/test-runner-coverage.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -583,27 +583,30 @@ test('coverage ignore comments exclude branches in LCOV output', skipIfNoInspect
583583
assert.strictEqual(result.status, 0);
584584

585585
// Extract the source.js section from LCOV output
586-
const sourceSection = lcov.split('end_of_record')
587-
.find((s) => s.includes('source.js'));
586+
const sourceSection = lcov.split('end_of_record').find((s) => s.includes('source.js'));
588587
assert(sourceSection, 'LCOV should contain source.js coverage');
589588

590589
// Verify that all branches are reported as covered (BRH should equal BRF)
591590
// The ignored branch should not penalize coverage
592591
const brfMatch = sourceSection.match(/BRF:(\d+)/);
593592
const brhMatch = sourceSection.match(/BRH:(\d+)/);
594-
assert(brfMatch, 'LCOV should contain BRF');
595-
assert(brhMatch, 'LCOV should contain BRH');
596-
assert.strictEqual(brfMatch[1], brhMatch[1],
597-
`All branches should be covered when ignored code is not executed. ` +
598-
`BRF=${brfMatch[1]}, BRH=${brhMatch[1]}`);
593+
assert.match(sourceSection, /BRF:(\d+)/, 'LCOV should contain BRF');
594+
assert.match(sourceSection, /BRH:(\d+)/, 'LCOV should contain BRH');
595+
assert.strictEqual(
596+
brfMatch[1],
597+
brhMatch[1],
598+
`All branches should be covered when ignored code is not executed. BRF=${brfMatch[1]}, BRH=${brhMatch[1]}`,
599+
);
599600

600601
// Verify no BRDA entries show 0 (uncovered) for the ignored branch
601602
// The branch at the if statement should be covered, not penalized by the ignored return
602603
const brdaEntries = sourceSection.match(/BRDA:\d+,\d+,\d+,(\d+)/g) || [];
603604
for (const entry of brdaEntries) {
604605
const count = entry.match(/BRDA:\d+,\d+,\d+,(\d+)/)[1];
605-
assert.notStrictEqual(count, '0',
606-
`No branch should show 0 coverage when the ` +
607-
`uncovered path is ignored: ${entry}`);
606+
assert.notStrictEqual(
607+
count,
608+
'0',
609+
`No branch should show 0 coverage when the uncovered path is ignored: ${entry}`,
610+
);
608611
}
609612
});

0 commit comments

Comments
 (0)