Skip to content

test_runner: expand directory arguments to find test files - #64824

Open
aalhadxx wants to merge 1 commit into
nodejs:mainfrom
aalhadxx:fix-test-runner-directory-args
Open

test_runner: expand directory arguments to find test files#64824
aalhadxx wants to merge 1 commit into
nodejs:mainfrom
aalhadxx:fix-test-runner-directory-args

Conversation

@aalhadxx

Copy link
Copy Markdown

When a directory is passed as an argument to node --test, the test runner treats it as a file pattern. Node.js internal Glob matches the directory itself, causing MODULE_NOT_FOUND when the runner tries to import the directory as a module.

This restores the pre-v21 behavior by detecting directory arguments and expanding them to search for default test file patterns within them.

Fixes: #64555

When a directory is passed as an argument to node --test, the test
runner treats it as a file pattern. Node.js internal Glob matches the
directory itself, causing MODULE_NOT_FOUND when the runner tries to
import the directory as a module.

This restores the pre-v21 behavior by detecting directory arguments and
expanding them to search for default test file patterns within them.

Fixes: nodejs#64555
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem. labels Jul 29, 2026
@atlowChemi atlowChemi added the semver-major PRs that contain breaking changes and should be released in the next major version. label Jul 30, 2026
@atlowChemi

Copy link
Copy Markdown
Member

Why do we want this though instead of dir/** etc?

@aalhadxx

Copy link
Copy Markdown
Author

Hi @atlowChemi, thanks for the question.

dir/** works when the shell expands it, but that is not universally available:

  • On Windows, cmd.exe and PowerShell do not expand ** globs before passing arguments to Node.
  • Even on Unix, if the user quotes the path or runs via a script/tooling that does not shell-expand, the literal string dir/** reaches Node unchanged.

Prior to v21, passing a directory to node --test was automatically expanded to search for default test patterns inside that directory. After the internal glob refactor, the directory itself was treated as a file pattern, leading to MODULE_NOT_FOUND when the runner tried to require() the directory as a module (see #64555).

This change restores the pre-v21 behavior: when an argument resolves to a directory, append the default test pattern so the runner searches inside it. Users who want explicit glob control can still pass dir/**/*.test.js, but the bare directory case should not error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. semver-major PRs that contain breaking changes and should be released in the next major version. test_runner Issues and PRs related to the test runner subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test_runner: directory arguments to --test fail with MODULE_NOT_FOUND on Windows (regression since v20)

3 participants