Skip to content

Commit

Permalink
test_runner: change ts default glob
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-ippolito committed Mar 7, 2025
1 parent 4cc69f9 commit fd014be
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 9 deletions.
9 changes: 3 additions & 6 deletions doc/api/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,9 @@ By default, Node.js will run all files matching these patterns:
Unless [`--no-experimental-strip-types`][] is supplied, the following
additional patterns are also matched:

* `**/*.test.{cts,mts,ts}`
* `**/*-test.{cts,mts,ts}`
* `**/*_test.{cts,mts,ts}`
* `**/test-*.{cts,mts,ts}`
* `**/test.{cts,mts,ts}`
* `**/test/**/*.{cts,mts,ts}`
* `**/test/**/*-test.{cts,mts,ts}`
* `**/test/**/*.test.{cts,mts,ts}`
* `**/test/**/*_test.{cts,mts,ts}`

Alternatively, one or more glob patterns can be provided as the
final argument(s) to the Node.js command, as shown below.
Expand Down
4 changes: 4 additions & 0 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const {
convertStringToRegExp,
countCompletedTest,
kDefaultPattern,
kDefaultTSPattern,
parseCommandLine,
} = require('internal/test_runner/utils');
const { Glob } = require('internal/fs/glob');
Expand All @@ -109,6 +110,9 @@ function createTestFileList(patterns, cwd) {
const hasUserSuppliedPattern = patterns != null;
if (!patterns || patterns.length === 0) {
patterns = [kDefaultPattern];
if (getOptionValue('--experimental-strip-types')) {
ArrayPrototypePush(patterns, kDefaultTSPattern);
}
}
const glob = new Glob(patterns, {
__proto__: null,
Expand Down
9 changes: 6 additions & 3 deletions lib/internal/test_runner/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ const kRegExpPattern = /^\/(.*)\/([a-z]*)$/;

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

const kDefaultTSPattern = '**/test/**/*{-,.,_}test.{cts,mts,ts}';

function createDeferredCallback() {
let calledCount = 0;
const { promise, resolve, reject } = PromiseWithResolvers();
Expand Down Expand Up @@ -291,6 +290,9 @@ function parseCommandLine() {
// TODO(pmarchini): this default should follow something similar to c8 defaults
// Default exclusions should be also exported to be used by other tools / users
coverageExcludeGlobs = [kDefaultPattern];
if (getOptionValue('--experimental-strip-types')) {
ArrayPrototypePush(coverageExcludeGlobs, kDefaultTSPattern);
}
}
coverageIncludeGlobs = getOptionValue('--test-coverage-include');

Expand Down Expand Up @@ -605,6 +607,7 @@ module.exports = {
createDeferredCallback,
isTestFailureError,
kDefaultPattern,
kDefaultTSPattern,
parseCommandLine,
reporterScope,
shouldColorizeTestFiles,
Expand Down

0 comments on commit fd014be

Please sign in to comment.