Skip to content

Commit fd014be

Browse files
test_runner: change ts default glob
1 parent 4cc69f9 commit fd014be

File tree

6 files changed

+13
-9
lines changed

6 files changed

+13
-9
lines changed

β€Ždoc/api/test.md

+3-6
Original file line numberDiff line numberDiff line change
@@ -418,12 +418,9 @@ By default, Node.js will run all files matching these patterns:
418418
Unless [`--no-experimental-strip-types`][] is supplied, the following
419419
additional patterns are also matched:
420420

421-
* `**/*.test.{cts,mts,ts}`
422-
* `**/*-test.{cts,mts,ts}`
423-
* `**/*_test.{cts,mts,ts}`
424-
* `**/test-*.{cts,mts,ts}`
425-
* `**/test.{cts,mts,ts}`
426-
* `**/test/**/*.{cts,mts,ts}`
421+
* `**/test/**/*-test.{cts,mts,ts}`
422+
* `**/test/**/*.test.{cts,mts,ts}`
423+
* `**/test/**/*_test.{cts,mts,ts}`
427424

428425
Alternatively, one or more glob patterns can be provided as the
429426
final argument(s) to the Node.js command, as shown below.

β€Žlib/internal/test_runner/runner.js

+4
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ const {
8383
convertStringToRegExp,
8484
countCompletedTest,
8585
kDefaultPattern,
86+
kDefaultTSPattern,
8687
parseCommandLine,
8788
} = require('internal/test_runner/utils');
8889
const { Glob } = require('internal/fs/glob');
@@ -109,6 +110,9 @@ function createTestFileList(patterns, cwd) {
109110
const hasUserSuppliedPattern = patterns != null;
110111
if (!patterns || patterns.length === 0) {
111112
patterns = [kDefaultPattern];
113+
if (getOptionValue('--experimental-strip-types')) {
114+
ArrayPrototypePush(patterns, kDefaultTSPattern);
115+
}
112116
}
113117
const glob = new Glob(patterns, {
114118
__proto__: null,

β€Žlib/internal/test_runner/utils.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,10 @@ const kRegExpPattern = /^\/(.*)\/([a-z]*)$/;
5555

5656
const kPatterns = ['test', 'test/**/*', 'test-*', '*[._-]test'];
5757
const kFileExtensions = ['js', 'mjs', 'cjs'];
58-
if (getOptionValue('--experimental-strip-types')) {
59-
ArrayPrototypePush(kFileExtensions, 'ts', 'mts', 'cts');
60-
}
6158
const kDefaultPattern = `**/{${ArrayPrototypeJoin(kPatterns, ',')}}.{${ArrayPrototypeJoin(kFileExtensions, ',')}}`;
6259

60+
const kDefaultTSPattern = '**/test/**/*{-,.,_}test.{cts,mts,ts}';
61+
6362
function createDeferredCallback() {
6463
let calledCount = 0;
6564
const { promise, resolve, reject } = PromiseWithResolvers();
@@ -291,6 +290,9 @@ function parseCommandLine() {
291290
// TODO(pmarchini): this default should follow something similar to c8 defaults
292291
// Default exclusions should be also exported to be used by other tools / users
293292
coverageExcludeGlobs = [kDefaultPattern];
293+
if (getOptionValue('--experimental-strip-types')) {
294+
ArrayPrototypePush(coverageExcludeGlobs, kDefaultTSPattern);
295+
}
294296
}
295297
coverageIncludeGlobs = getOptionValue('--test-coverage-include');
296298

@@ -605,6 +607,7 @@ module.exports = {
605607
createDeferredCallback,
606608
isTestFailureError,
607609
kDefaultPattern,
610+
kDefaultTSPattern,
608611
parseCommandLine,
609612
reporterScope,
610613
shouldColorizeTestFiles,

0 commit comments

Comments
Β (0)