Repository: nodejs/node
Pull request: Revert "test_runner: change ts default glob"

<!--
Before submitting a pull request, please read:

- the CONTRIBUTING guide at https://github.com/nodejs/node/blob/HEAD/CONTRIBUTING.md
- the commit message formatting guidelines at
  https://github.com/nodejs/node/blob/HEAD/doc/contributing/pull-requests.md#commit-message-guidelines

For code changes:
1. Include tests for any bug fixes or new features.
2. Update documentation if relevant.
3. Ensure that `make -j4 test` (UNIX), or `vcbuild test` (Windows) passes.

If you believe this PR should be highlighted in the Node.js CHANGELOG
please add the `notable-change` label.

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.
-->

TypeScript files glob for the test runner was added in #55081, and then changed in #57359. With this PR, I would like that we revert #57359, or at least open the discussion. Great default, and a runtime which just "work out of the box" is important, that's why changing the defaults matter.

Why should TypeScript files have different globs than JavaScript files?
It was already suggested that for v24.0.0, we remove this restriction of the test folder: https://github.com/nodejs/node/pull/57359#issuecomment-2706744075.

As we are approaching the stabilization of the TypeScript strip types feature, it is now or "never" (or only able to change that in semver major versions) to change the defaults, since it is still experimental for now, there is still time to do it.

Today, I wanted to try Node.js v24.0.0, and since v24 obviously include everything from v23 and v23 includes #57359, I was surprised that my tests were ignored (upgrading from v22).

https://github.com/nodejs/node/pull/57359#issuecomment-2706781166
> I think the issue is that people keep their `test.ts` in the `src` folder and transpile them, so they will be executed twice. Once node v20 goes EOL we can be more lax and include other patterns

Why should people transpile test files, if it's possible to run them without transpiling thanks to that strip types feature? (I indeed keep my TypeScript files under a `src` folder).

Changed files:
filename: doc/api/test.md
patch: @@ -472,9 +472,12 @@ 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/**/*-test.{cts,mts,ts}`
-* `**/test/**/*.test.{cts,mts,ts}`
-* `**/test/**/*_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/**/*.{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.

filename: lib/internal/test_runner/runner.js
patch: @@ -110,7 +110,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,

filename: lib/internal/test_runner/utils.js
patch: @@ -60,10 +60,10 @@ 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(kDefaultPattern, '**/test/**/*{-,.,_}test.{cts,mts,ts}');
+  ArrayPrototypePush(kFileExtensions, 'ts', 'mts', 'cts');
 }
+const kDefaultPattern = `**/{${ArrayPrototypeJoin(kPatterns, ',')}}.{${ArrayPrototypeJoin(kFileExtensions, ',')}}`;
 
 function createDeferredCallback() {
   let calledCount = 0;
@@ -295,7 +295,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');