From fd014be50734bddd0286126cf5224212c86682a3 Mon Sep 17 00:00:00 2001 From: Marco Ippolito Date: Fri, 7 Mar 2025 13:49:42 +0100 Subject: [PATCH] test_runner: change ts default glob --- doc/api/test.md | 9 +++------ lib/internal/test_runner/runner.js | 4 ++++ lib/internal/test_runner/utils.js | 9 ++++++--- .../matching-patterns/{ => test}/typescript-test.cts | 0 .../matching-patterns/{ => test}/typescript-test.mts | 0 .../matching-patterns/{ => test}/typescript-test.ts | 0 6 files changed, 13 insertions(+), 9 deletions(-) rename test/fixtures/test-runner/matching-patterns/{ => test}/typescript-test.cts (100%) rename test/fixtures/test-runner/matching-patterns/{ => test}/typescript-test.mts (100%) rename test/fixtures/test-runner/matching-patterns/{ => test}/typescript-test.ts (100%) diff --git a/doc/api/test.md b/doc/api/test.md index 04747c80f85006..a6cb00cd362ece 100644 --- a/doc/api/test.md +++ b/doc/api/test.md @@ -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. diff --git a/lib/internal/test_runner/runner.js b/lib/internal/test_runner/runner.js index 43a62b5b4307e4..6d23c843a6a5b0 100644 --- a/lib/internal/test_runner/runner.js +++ b/lib/internal/test_runner/runner.js @@ -83,6 +83,7 @@ const { convertStringToRegExp, countCompletedTest, kDefaultPattern, + kDefaultTSPattern, parseCommandLine, } = require('internal/test_runner/utils'); const { Glob } = require('internal/fs/glob'); @@ -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, diff --git a/lib/internal/test_runner/utils.js b/lib/internal/test_runner/utils.js index 8e0a920ea7756f..a0e5415f7506f4 100644 --- a/lib/internal/test_runner/utils.js +++ b/lib/internal/test_runner/utils.js @@ -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(); @@ -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'); @@ -605,6 +607,7 @@ module.exports = { createDeferredCallback, isTestFailureError, kDefaultPattern, + kDefaultTSPattern, parseCommandLine, reporterScope, shouldColorizeTestFiles, diff --git a/test/fixtures/test-runner/matching-patterns/typescript-test.cts b/test/fixtures/test-runner/matching-patterns/test/typescript-test.cts similarity index 100% rename from test/fixtures/test-runner/matching-patterns/typescript-test.cts rename to test/fixtures/test-runner/matching-patterns/test/typescript-test.cts diff --git a/test/fixtures/test-runner/matching-patterns/typescript-test.mts b/test/fixtures/test-runner/matching-patterns/test/typescript-test.mts similarity index 100% rename from test/fixtures/test-runner/matching-patterns/typescript-test.mts rename to test/fixtures/test-runner/matching-patterns/test/typescript-test.mts diff --git a/test/fixtures/test-runner/matching-patterns/typescript-test.ts b/test/fixtures/test-runner/matching-patterns/test/typescript-test.ts similarity index 100% rename from test/fixtures/test-runner/matching-patterns/typescript-test.ts rename to test/fixtures/test-runner/matching-patterns/test/typescript-test.ts