Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Node v21] node --test executes tests twice if they are in folder named test #50875

Closed
Ngorror opened this issue Nov 23, 2023 · 0 comments · Fixed by #50881
Closed

[Node v21] node --test executes tests twice if they are in folder named test #50875

Ngorror opened this issue Nov 23, 2023 · 0 comments · Fixed by #50881
Labels
confirmed-bug Issues with confirmed bugs. fs Issues and PRs related to the fs subsystem / file system. test_runner Issues and PRs related to the test runner subsystem.

Comments

@Ngorror
Copy link

Ngorror commented Nov 23, 2023

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

  1. create a folder for your project mkdir issue1
  2. go to the project folder cd issue1
  3. init the project npm init
  4. 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"
}
  1. create test sub-folder mkdir test
  2. create test case file bug.test.js in the test 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 named test
  • 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

@MoLow MoLow added confirmed-bug Issues with confirmed bugs. fs Issues and PRs related to the fs subsystem / file system. test_runner Issues and PRs related to the test runner subsystem. labels Nov 23, 2023
nodejs-github-bot pushed a commit that referenced this issue Nov 26, 2023
PR-URL: #50881
Fixes: #50875
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
martenrichter pushed a commit to martenrichter/node that referenced this issue Nov 26, 2023
PR-URL: nodejs#50881
Fixes: nodejs#50875
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
lucshi pushed a commit to lucshi/node that referenced this issue Nov 27, 2023
PR-URL: nodejs#50881
Fixes: nodejs#50875
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
RafaelGSS pushed a commit that referenced this issue Nov 27, 2023
PR-URL: #50881
Fixes: #50875
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
RafaelGSS pushed a commit that referenced this issue Nov 29, 2023
PR-URL: #50881
Fixes: #50875
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
RafaelGSS pushed a commit that referenced this issue Nov 30, 2023
PR-URL: #50881
Fixes: #50875
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. fs Issues and PRs related to the fs subsystem / file system. test_runner Issues and PRs related to the test runner subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants