Skip to content

Commit 7c71dd0

Browse files
committed
test_runner: apply default test-file exclusion via run() API
The CLI path defaults coverageExcludeGlobs to [kDefaultPattern] when --experimental-test-coverage is set, dropping test files from the coverage report. The run() API skipped this default, so callers got test files mixed into their coverage data. Apply the same default when run() is invoked with coverage: true and no explicit coverageExcludeGlobs, so both entry points behave consistently. Update the existing run() coverage tests that depended on the absent default to opt out via coverageExcludeGlobs: '!test/**'. Refs: #60023 Signed-off-by: sangwook <rewq5991@gmail.com>
1 parent 8b5b331 commit 7c71dd0

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

lib/internal/test_runner/runner.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,8 @@ function run(options = kEmptyObject) {
805805
coverageExcludeGlobs = [coverageExcludeGlobs];
806806
}
807807
validateStringArray(coverageExcludeGlobs, 'options.coverageExcludeGlobs');
808+
} else if (coverage) {
809+
coverageExcludeGlobs = [kDefaultPattern];
808810
}
809811
if (coverageIncludeGlobs != null) {
810812
if (!ArrayIsArray(coverageIncludeGlobs)) {

test/parallel/test-runner-run-coverage.mjs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ describe('require(\'node:test\').run coverage settings', { concurrency: true },
123123
const stream = run({
124124
files,
125125
coverage: true,
126+
coverageExcludeGlobs: '!test/**',
126127
coverageIncludeGlobs: ['test/fixtures/test-runner/coverage.js', 'test/*/v8-coverage/throw.js'],
127128
});
128129
stream.on('test:fail', common.mustNotCall());
@@ -157,7 +158,14 @@ describe('require(\'node:test\').run coverage settings', { concurrency: true },
157158
const thresholdErrors = [];
158159
const originalExitCode = process.exitCode;
159160
assert.notStrictEqual(originalExitCode, 1);
160-
const stream = run({ files, coverage: true, lineCoverage: 99, branchCoverage: 99, functionCoverage: 99 });
161+
const stream = run({
162+
files,
163+
coverage: true,
164+
coverageExcludeGlobs: '!test/**',
165+
lineCoverage: 99,
166+
branchCoverage: 99,
167+
functionCoverage: 99,
168+
});
161169
stream.on('test:fail', common.mustNotCall());
162170
stream.on('test:pass', common.mustCall(1));
163171
stream.on('test:diagnostic', ({ message }) => {

0 commit comments

Comments
 (0)