-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
Closed
Labels
confirmed-bugIssues with confirmed bugs.Issues with confirmed bugs.test_runnerIssues and PRs related to the test runner subsystem.Issues and PRs related to the test runner subsystem.
Description
Version
21.6.1
Platform
darwin
Subsystem
test runner
What steps will reproduce the bug?
Create a file called hooks.mjs
containing:
import { describe, afterEach, after, it } from 'node:test';
describe('parent', () => {
afterEach(() => console.log('parent after each'));
after(() => console.log('parent after'));
describe('child', () => {
afterEach(() => console.log('child after each'));
after(() => console.log('child after'));
it('works', () => {});
});
});
and run node --test hooks.mjs
.
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
child after each
parent after each
child after
parent after
<test results>
As with mocha
, qunit
, jest
, vitest
, and probably others, a child suite's afterEach
hooks should be called before those of parent suites, not after them. Also, the execution order of parent/child afterEach
hooks should match the order of parent/child after
hooks.
Currently, after
hooks correctly run child-first, but afterEach
hooks run incorrectly parent-first.
What do you see instead?
parent after each
child after each
child after
parent after
<test results>
Additional information
This also reproduces with the test()
/subtest API -- a test's afterEach
hook will run before a subtest's afterEach
hook.
marco-ippolito and tonivj5tonivj5
Metadata
Metadata
Assignees
Labels
confirmed-bugIssues with confirmed bugs.Issues with confirmed bugs.test_runnerIssues and PRs related to the test runner subsystem.Issues and PRs related to the test runner subsystem.