Version
test_runner: directory arguments to --test fail with MODULE_NOT_FOUND (regression since v20, all platforms)
Platform
Microsoft Windows NT 10.0.26200.0 x64
Subsystem
test_runner
What steps will reproduce the bug?
Create a directory containing a single test file:
tests/sample.test.mjs:
import test from 'node:test';
test('ok', () => {});
Then, on Windows, pass the directory to the test runner:
node --test tests
node --test tests/
node --test tests\
All three fail with MODULE_NOT_FOUND — the directory is executed as if it
were a test file instead of being searched for test files.
For contrast, all of the following work:
node --test with no arguments in the same folder (default discovery finds and runs the test)
- the same three commands on Node v20.20.2 on Windows
- passing a directory on Linux/macOS
How often does it reproduce? Is there a required condition?
Always, on Windows, whenever a directory path is passed as an argument to --test.
What is the expected behavior? Why is that the expected behavior?
Passing a directory to node --test should recursively search it for test
files and run them, as documented, as Node v20 does on Windows, and as current
versions still do on Linux/macOS.
What do you see instead?
The directory is treated as a single test file and executed directly, which
fails in the module loader:
PS C:\Users\KIIT\node-bug-repro> node --test tests/
node:internal/modules/cjs/loader:1368
throw err;
^
Error: Cannot find module 'C:\Users\KIIT\node-bug-repro\tests'
at Function._resolveFilename (node:internal/modules/cjs/loader:1365:15)
at defaultResolveImpl (node:internal/modules/cjs/loader:1021:19)
at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1026:22)
at Function._load (node:internal/modules/cjs/loader:1175:37)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:171:5)
at node:internal/main/run_main_module:36:49 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v22.18.0
✖ tests (70.2044ms)
'test failed'
ℹ tests 1
ℹ suites 0
ℹ pass 0
ℹ fail 1
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 79.0802
✖ failing tests:
test at tests:1:1
✖ tests (70.2044ms)
'test failed'
The output is identical for node --test tests and node --test tests\.
Additional information
This appears to be a regression between v20.20.2 (works) and v22.x (broken).
Possibly related to the test runner's file discovery moving to the internal
glob implementation (createTestFileList in lib/internal/test_runner/runner.js),
where a directory pattern seems to match the directory itself rather than
being expanded to the test files inside it.
Happy to work on a fix if a collaborator confirms this is a bug.
Version
test_runner: directory arguments to --test fail with MODULE_NOT_FOUND (regression since v20, all platforms)
Platform
Subsystem
test_runner
What steps will reproduce the bug?
Create a directory containing a single test file:
tests/sample.test.mjs:Then, on Windows, pass the directory to the test runner:
All three fail with
MODULE_NOT_FOUND— the directory is executed as if itwere a test file instead of being searched for test files.
For contrast, all of the following work:
node --testwith no arguments in the same folder (default discovery finds and runs the test)How often does it reproduce? Is there a required condition?
Always, on Windows, whenever a directory path is passed as an argument to --test.
What is the expected behavior? Why is that the expected behavior?
Passing a directory to
node --testshould recursively search it for testfiles and run them, as documented, as Node v20 does on Windows, and as current
versions still do on Linux/macOS.
What do you see instead?
The directory is treated as a single test file and executed directly, which
fails in the module loader:
The output is identical for
node --test testsandnode --test tests\.Additional information
This appears to be a regression between v20.20.2 (works) and v22.x (broken).
Possibly related to the test runner's file discovery moving to the internal
glob implementation (
createTestFileListinlib/internal/test_runner/runner.js),where a directory pattern seems to match the directory itself rather than
being expanded to the test files inside it.
Happy to work on a fix if a collaborator confirms this is a bug.