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

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

Closed
rluvaton opened this issue Jul 25, 2023 · 4 comments · Fixed by #48925
Labels
test_runner Issues and PRs related to the test runner subsystem.

Comments

@rluvaton
Copy link
Member

rluvaton commented Jul 25, 2023

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

@MoLow MoLow added the test_runner Issues and PRs related to the test runner subsystem. label Jul 25, 2023
@atlowChemi
Copy link
Member

@rluvaton isn't this behavior expected?
the before hook is probably being used to set the state, and if it failed the test would fail?

@rluvaton
Copy link
Member Author

Hey, we are talking about beforeEach not before

@atlowChemi
Copy link
Member

I still think my point is valid in that case 🙂

@rluvaton
Copy link
Member Author

rluvaton commented Jul 26, 2023

the scenario is:
first beforeEach fails and the rest does not, the problem here is the 2nd beforeEach marked as failed even when it shouldn't, take a look again at the code example

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

Successfully merging a pull request may close this issue.

3 participants