Skip to content

Watch mode duplicates and fails on second run #52936

@MayaLi

Description

@MayaLi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    test_runnerIssues and PRs related to the test runner subsystem.watch-modeIssues and PRs related to watch mode

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions