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

Watch mode duplicates and fails on second run #52936

Closed
MayaLi opened this issue May 10, 2024 · 1 comment · Fixed by #52954
Closed

Watch mode duplicates and fails on second run #52936

MayaLi opened this issue May 10, 2024 · 1 comment · Fixed by #52954
Labels
test_runner watch-mode Issues and PRs related to watch mode

Comments

@MayaLi
Copy link

MayaLi commented May 10, 2024

Version

v22.1.0

Platform

Darwin Mayas-Personal-MacBook-Pro.local 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:11:05 PDT 2024; root:xnu-10063.101.17~1/RELEASE_X86_64 x86_64

Subsystem

No response

What steps will reproduce the bug?

I wrote a simple function and test as the following. node --test runs successfully. node --test --watch runs the test twice and fails on the second run.

// src/controllers/ping.ts 
export function ping(): string {
    return "pong";
}

Test:

// src/controllers/ping.test.ts 
import { describe, it } from 'node:test';
import assert from 'node:assert';
import { ping } from "./ping";


describe("ping controller tests", () => {
    it("should respond pong", () => {
        assert.strictEqual(ping(), "pong");
    });
});

When I run node --test, it succeeds.

> tsc --noEmit && node --import tsx --test **/*.test.ts

▶ ping controller tests
  ✔ should respond pong (1.001501ms)
▶ ping controller tests (2.188658ms)
ℹ tests 1
ℹ suites 1
ℹ pass 1
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 370.149275

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

Consistently every time.

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

I expect the runner to stop after the first run with success. When a change is made to the test file, the changed test file is run only once again.

What do you see instead?

When I ran node --test --watch, the same test was run twice failing the second time with test did not finish before its parent and was cancelled error message.

> tsc --noEmit && node --import tsx --test --watch src/**/*.test.ts

▶ ping controller tests
  ✔ should respond pong (0.938915ms)
▶ ping controller tests (2.118648ms)
✖ src/controllers/ping.test.ts (306.529408ms)
  'test did not finish before its parent and was cancelled'

ℹ tests 2
ℹ suites 1
ℹ pass 1
ℹ fail 0
ℹ cancelled 1
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 318.039034

Additional information

No response

@VoltrexKeyva VoltrexKeyva added the watch-mode Issues and PRs related to watch mode label May 10, 2024
@benjamingr
Copy link
Member

@MoLow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test_runner watch-mode Issues and PRs related to watch mode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants