Skip to content

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

@EndangeredMassa

Description

@EndangeredMassa

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

> test@1.0.0 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

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