-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Order of nested vs outer afterEach
hooks is unexpected and inconsistent with after
#51671
Labels
confirmed-bug
Issues with confirmed bugs.
test_runner
Issues and PRs related to the test runner subsystem.
Comments
marco-ippolito
added
the
test_runner
Issues and PRs related to the test runner subsystem.
label
Feb 7, 2024
I agree subtest This works fine: 'use strict';
require('../common');
const assert = require('node:assert');
const { test, afterEach, after } = require('node:test');
let afterEachRacing = true;
let afterRacing = true;
test('parent', () => {
afterEach(() => afterEachRacing = false);
after(() => afterRacing = false);
test('child', () => {
afterEach(() => assert.ok(afterEachRacing));
after(() => assert.ok(afterRacing));
test(() => { });
});
}); this fails: 'use strict';
require('../common');
const assert = require('node:assert');
const { describe, it, afterEach, after } = require('node:test');
let afterEachRacing = true;
let afterRacing = true;
describe('parent', () => {
afterEach(() => afterEachRacing = false);
after(() => afterRacing = false);
describe('child', () => {
afterEach(() => assert.ok(afterEachRacing));
after(() => assert.ok(afterRacing));
it(() => { });
});
}); |
I meant that test('parent', async (t) => {
t.afterEach((c) => console.log('parent after each', c.name));
t.after((c) => console.log('parent after', c.name));
await t.test('child', async (t) => {
t.afterEach((c) => console.log('child after each', c.name));
t.after((c) => console.log('child after', c.name));
await t.test('works', () => {});
});
}); produces
instead of
so the parent's afterEach for |
cjihrig
added a commit
to cjihrig/node
that referenced
this issue
Mar 28, 2024
This commit updates the test runner afterEach hook so that the current test's afterEach hooks run before any ancestor afterEach hooks. Fixes: nodejs#51671
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
confirmed-bug
Issues with confirmed bugs.
test_runner
Issues and PRs related to the test runner subsystem.
Version
21.6.1
Platform
darwin
Subsystem
test runner
What steps will reproduce the bug?
Create a file called
hooks.mjs
containing: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?
As with
mocha
,qunit
,jest
,vitest
, and probably others, a child suite'safterEach
hooks should be called before those of parent suites, not after them. Also, the execution order of parent/childafterEach
hooks should match the order of parent/childafter
hooks.Currently,
after
hooks correctly run child-first, butafterEach
hooks run incorrectly parent-first.What do you see instead?
Additional information
This also reproduces with the
test()
/subtest API -- a test'safterEach
hook will run before a subtest'safterEach
hook.The text was updated successfully, but these errors were encountered: