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

Global "before" hook never seems to be executed #47518

Closed
EndangeredMassa opened this issue Apr 11, 2023 · 2 comments · Fixed by #47586
Closed

Global "before" hook never seems to be executed #47518

EndangeredMassa opened this issue Apr 11, 2023 · 2 comments · Fixed by #47586
Labels
test_runner Issues and PRs related to the test runner subsystem.

Comments

@EndangeredMassa
Copy link

EndangeredMassa commented Apr 11, 2023

Version

v19.9.0

Platform

Darwin Vercel-Macbook 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 arm64

Subsystem

No response

What steps will reproduce the bug?

Create a test file with:

import { it, describe, before, beforeEach, after, afterEach } from 'node:test';
import assert from 'node:assert';

before(() => console.log('before!'));
beforeEach(() => console.log('beforeEach!'));

describe('nest group', async () => {
  it('inside test', () => {
    assert.ok('some relevant assertion here');
  });
});

it('outside test', () => {
  assert.ok('some relevant assertion here');
});

and run it with something like node some.test.js.

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

always

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

The output should show log messages from before once and beforeAll twice.

What do you see instead?

The outpu shows log messages from before never and beforeAll twice.

Example Output:

$  npm test

> [email protected] test
> node sum.test.mjs

beforeEach!
beforeEach!
▶ nest group
  ✔ inside test (0.132667ms)
▶ nest group (1.331583ms)

✔ outside test (0.112125ms)
ℹ tests 2
ℹ suites 1
ℹ pass 2
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 4.670792

Additional information

No response

@VoltrexKeyva VoltrexKeyva added the test_runner Issues and PRs related to the test runner subsystem. label Apr 12, 2023
@MoLow
Copy link
Member

MoLow commented Apr 13, 2023

the reason is before hook is only set-up to run on describe not on test and the root test tree is a test, not a suite.
@atlowChemi do you want to take this issue?

@atlowChemi
Copy link
Member

@MoLow Yeah, I'd be happy to take this 👍🏽

atlowChemi added a commit to atlowChemi/node that referenced this issue Apr 16, 2023
Execute the before hook for Test as well, and execute it on root before
executing any tests.

Fixes: nodejs#47518
atlowChemi added a commit to atlowChemi/node that referenced this issue Apr 16, 2023
Execute the before hook for Test as well, and execute it on root before
executing any tests.

Fixes: nodejs#47518
atlowChemi added a commit to atlowChemi/node that referenced this issue Apr 16, 2023
Execute the before hook for Test as well, and execute it on root before
executing any tests.

Fixes: nodejs#47518
atlowChemi added a commit to atlowChemi/node that referenced this issue Apr 16, 2023
Execute the before hook for Test as well, and execute it on root before
executing any tests.

Fixes: nodejs#47518
atlowChemi added a commit to atlowChemi/node that referenced this issue Apr 16, 2023
Execute the before hook for Test as well, and execute it on root before
executing any tests.

Fixes: nodejs#47518
atlowChemi added a commit to atlowChemi/node that referenced this issue Apr 16, 2023
Execute the before hook for Test as well, and execute it on root before
executing any tests.

Fixes: nodejs#47518
nodejs-github-bot pushed a commit that referenced this issue Apr 18, 2023
Execute the before hook for Test as well, and execute it on root before
executing any tests.

Fixes: #47518
PR-URL: #47586
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Moshe Atlow <[email protected]>
targos pushed a commit that referenced this issue May 2, 2023
Execute the before hook for Test as well, and execute it on root before
executing any tests.

Fixes: #47518
PR-URL: #47586
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Moshe Atlow <[email protected]>
danielleadams pushed a commit that referenced this issue Jul 6, 2023
Execute the before hook for Test as well, and execute it on root before
executing any tests.

Fixes: #47518
PR-URL: #47586
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Moshe Atlow <[email protected]>
MoLow pushed a commit to MoLow/node that referenced this issue Jul 6, 2023
Execute the before hook for Test as well, and execute it on root before
executing any tests.

Fixes: nodejs#47518
PR-URL: nodejs#47586
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Moshe Atlow <[email protected]>
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.

4 participants