Skip to content

test runner: global before doesn't run if there are no global test #48844

Closed
@alcuadrado

Description

@alcuadrado

Version

v20.4.0

Platform

Darwin lucille.lan 22.5.0 Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:23 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6020 arm64

Subsystem

test runner

What steps will reproduce the bug?

If you run this test with node --test, "before" is not printed.

import { describe, it, before, after } from "node:test";

before(async () => {
  console.log("before");
});

after(async () => {
  console.log("after");
});

describe("describe", async () => {
  it("it inside describe", async () => {});
});

If you define a test outside the describe, "before" is printed

import { describe, it, before, after } from "node:test";

before(async () => {
  console.log("before");
});

after(async () => {
  console.log("after");
});

describe("describe", async () => {
  it("it inside describe", async () => {});
});

it("it outside describe", async () => {});

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

It's deterministic.

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

The before hook should always run.

What do you see instead?

It only runs if I have a global test.

Additional information

after doesn't seem to be affected by this issue. It always runs. This makes me believe that the intended behavior of before matches my expectations.

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