Skip to content

beforeEach timeout cause further tests in the same suite (describe or root) to not be executed and treated as timed out #48917

@rluvaton

Description

@rluvaton

Version

20.5.0

Platform

Darwin razluvaton-macOS-1331-Raz-Luvaton-VGXFX99QJK.local 22.5.0 Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:20 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6000 arm64

Subsystem

test_runner

What steps will reproduce the bug?

because the hooks are the same instance they share the same this.signal which causes further tests to not execute due to this:

if (this[kShouldAbort]()) {
this.postRun();
return;
}

run this test:

const {beforeEach, test} = require("node:test");
const {setTimeout} = require("timers/promises");

let i = 0;
beforeEach(async () => {
  console.log(i)
  if (i++ === 0) {
    console.log('gonna timeout');
    await setTimeout(200);
    return;
  }
  console.log('regular');
}, {
  timeout: 100
});

test('a', () => {
  console.log('a');
});
test('b', () => {
  console.log('b');
});

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

always

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

should not abort the next

What do you see instead?

all tests are marked as timed out:

❯ node index.js
0
gonna timeout
✖ a (102.177667ms)
  'test timed out after 100ms'

✖ b (0.056458ms)
  'test timed out after 100ms'

ℹ tests 2
ℹ suites 0
ℹ pass 0
ℹ fail 2
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 0.514458

✖ failing tests:

✖ a (102.177667ms)
  'test timed out after 100ms'

✖ b (0.056458ms)
  'test timed out after 100ms'

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    test_runnerIssues and PRs related to the test runner subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions