|
2 | 2 | const common = require('../common'); |
3 | 3 | const assert = require('node:assert'); |
4 | 4 | const { spawnSync } = require('node:child_process'); |
5 | | -const { readdirSync } = require('node:fs'); |
| 5 | +const { readdirSync, writeFileSync } = require('node:fs'); |
6 | 6 | const { test } = require('node:test'); |
7 | 7 | const fixtures = require('../common/fixtures'); |
8 | 8 | const tmpdir = require('../common/tmpdir'); |
@@ -77,6 +77,43 @@ function getSpecCoverageFixtureReport() { |
77 | 77 | return report; |
78 | 78 | } |
79 | 79 |
|
| 80 | +test('lcov reporter excludes BRDA entries for ignored lines', skipIfNoInspector, () => { |
| 81 | + const fixture = tmpdir.resolve('lcov-ignore-branch.test.js'); |
| 82 | + |
| 83 | + writeFileSync(fixture, ` |
| 84 | +'use strict'; |
| 85 | +
|
| 86 | +const test = require('node:test'); |
| 87 | +
|
| 88 | +test('ignored branch', () => { |
| 89 | + // node:coverage ignore next |
| 90 | + if (false) { |
| 91 | + throw new Error('ignored'); |
| 92 | + } |
| 93 | +
|
| 94 | + if (true) { |
| 95 | + // Covered branch to ensure LCOV still reports branch data. |
| 96 | + } |
| 97 | +}); |
| 98 | +`); |
| 99 | + |
| 100 | + const child = spawnSync(process.execPath, [ |
| 101 | + '--test', |
| 102 | + '--experimental-test-coverage', |
| 103 | + '--test-reporter', |
| 104 | + 'lcov', |
| 105 | + fixture, |
| 106 | + ]); |
| 107 | + |
| 108 | + assert.strictEqual(child.stderr.toString(), ''); |
| 109 | + assert.strictEqual(child.status, 0); |
| 110 | + |
| 111 | + const stdout = child.stdout.toString(); |
| 112 | + |
| 113 | + assert(!stdout.includes('BRDA:8,')); |
| 114 | + assert.match(stdout, /BRDA:/); |
| 115 | +}); |
| 116 | + |
80 | 117 | test('test coverage report', async (t) => { |
81 | 118 | await t.test('handles the inspector not being available', (t) => { |
82 | 119 | if (process.features.inspector) { |
|
0 commit comments