nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
106.56k stars 29.05k forks source link

test_runner: `latest.js` file is included by default #54726

Closed hyunbinseo closed 3 days ago

hyunbinseo commented 1 week ago

Version

v22.7.0

Platform

No response

Subsystem

No response

What steps will reproduce the bug?

  1. Create an empty latest.js file
  2. Run the Node.js test runner
fnm use 20
# Using Node v20.17.0

node --test
# ℹ tests 0
# ℹ suites 0
# ℹ pass 0
# ℹ fail 0
# ℹ cancelled 0
# ℹ skipped 0
# ℹ todo 0
# ℹ duration_ms 4.365042
fnm use 22
# Using Node v22.7.0

node --test
# ✔ latest.js (43.960958ms)
# ℹ tests 1
# ℹ suites 0
# ℹ pass 1
# ℹ fail 0
# ℹ cancelled 0
# ℹ skipped 0
# ℹ todo 0
# ℹ duration_ms 53.687041

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

By default, Node.js will run all files matching these patterns:

**/*.test.?(c|m)js
**/*-test.?(c|m)js
**/*_test.?(c|m)js
**/test-*.?(c|m)js
**/test.?(c|m)js
**/test/**/*.?(c|m)js

https://nodejs.org/api/test.html#running-tests-from-the-command-line

What do you see instead?

latest.js filename does not match the above patterns, but is included in node --test

Additional information

No response

pmarchini commented 1 week ago

Hey @hyunbinseo , I believe this issue is caused by the following regex matching pattern: https://github.com/nodejs/node/blob/main/lib/internal/test_runner/utils.js#L54 -> *[.-_]test

I've created a repro and proposed a possible solution in this pull request: #54728.