From 844d7b0804414edb6b32ffa2a7bf82c6dd03c5d1 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 | 2 +- lib/internal/test_runner/utils.js | 7 ++++--- .../matching-patterns/{ => test}/typescript-test.cts | 0 .../matching-patterns/{ => test}/typescript-test.mts | 0 .../matching-patterns/{ => test}/typescript-test.ts | 0 6 files changed, 8 insertions(+), 10 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..733a745a494162 100644 --- a/lib/internal/test_runner/runner.js +++ b/lib/internal/test_runner/runner.js @@ -108,7 +108,7 @@ let kResistStopPropagation; function createTestFileList(patterns, cwd) { const hasUserSuppliedPattern = patterns != null; if (!patterns || patterns.length === 0) { - patterns = [kDefaultPattern]; + patterns = kDefaultPattern; } 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..8672597603f6f5 100644 --- a/lib/internal/test_runner/utils.js +++ b/lib/internal/test_runner/utils.js @@ -55,10 +55,11 @@ const kRegExpPattern = /^\/(.*)\/([a-z]*)$/; const kPatterns = ['test', 'test/**/*', 'test-*', '*[._-]test']; const kFileExtensions = ['js', 'mjs', 'cjs']; +const kDefaultPattern = [`**/{${ArrayPrototypeJoin(kPatterns, ',')}}.{${ArrayPrototypeJoin(kFileExtensions, ',')}}`]; if (getOptionValue('--experimental-strip-types')) { - ArrayPrototypePush(kFileExtensions, 'ts', 'mts', 'cts'); + const kDefaultTSPattern = '**/test/**/*{-,.,_}test.{cts,mts,ts}'; + ArrayPrototypePush(kDefaultPattern, kDefaultTSPattern); } -const kDefaultPattern = `**/{${ArrayPrototypeJoin(kPatterns, ',')}}.{${ArrayPrototypeJoin(kFileExtensions, ',')}}`; function createDeferredCallback() { let calledCount = 0; @@ -290,7 +291,7 @@ function parseCommandLine() { if (!coverageExcludeGlobs || coverageExcludeGlobs.length === 0) { // 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]; + coverageExcludeGlobs = kDefaultPattern; } coverageIncludeGlobs = getOptionValue('--test-coverage-include'); 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