Closed
Description
Version
21.2.0
Platform
Linux DEU1118 6.2.0-37-generic #38~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Nov 2 18:01:13 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
Preparation
- create a folder for your project
mkdir issue1
- go to the project folder
cd issue1
- init the project
npm init
- add to package.json
"type": "module"
. at the end it will look like this
{
"name": "issue1",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"type": "module"
}
- create
test
sub-foldermkdir test
- create test case file
bug.test.js
in thetest
sub-folder with the following content
import { describe, it } from "node:test";
describe("Test", () => {
it("Test", () => {});
});
How to Reproduce
execute from the main folder node --test
the test will be executed twice. an example output:
▶ Test
✔ Test (0.155014ms)
▶ Test (1.222016ms)
▶ Test
✔ Test (0.155561ms)
▶ Test (1.22262ms)
ℹ tests 2
ℹ suites 2
ℹ pass 2
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 38.641146
How to "Fix"
rename your test
folder to something else: mv test mest
execute again from the main folder node --test
the test will be executed once. an example output:
▶ Test
✔ Test (0.127919ms)
▶ Test (1.088147ms)
ℹ tests 1
ℹ suites 1
ℹ pass 1
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 37.162391
How often does it reproduce? Is there a required condition?
It can be reproduced every single time
the required conditions are:
*.test.js
file(s) in a folder namedtest
- use
node
21.*
What is the expected behavior? Why is that the expected behavior?
The expected behavior is the test to be executed once:
▶ Test
✔ Test (0.127919ms)
▶ Test (1.088147ms)
ℹ tests 1
ℹ suites 1
ℹ pass 1
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 37.162391
This is the expected behavior because I have one single test in one single file in the whole project
What do you see instead?
Test was executed twice:
▶ Test
✔ Test (0.155014ms)
▶ Test (1.222016ms)
▶ Test
✔ Test (0.155561ms)
▶ Test (1.22262ms)
ℹ tests 2
ℹ suites 2
ℹ pass 2
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 38.641146
Additional information
No response