You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test runner runs beforeEach or test case before "before hook" finished #52764
importassertfrom"node:assert/strict";importtestfrom"node:test";import{setTimeout}from"node:timers/promises";awaittest("test suite",async(t)=>{t.before(async()=>{console.log("before start");awaitsetTimeout(100);console.log("before end");});t.beforeEach(async()=>{console.log("beforeEach start");awaitsetTimeout(100);console.log("beforeEach end");});t.afterEach(async()=>{console.log("afterEach start");awaitsetTimeout(100);console.log("afterEach end");});t.after(async()=>{console.log("after start");awaitsetTimeout(100);console.log("after end");});awaitt.test("test case",async()=>{console.log("test case start");awaitsetTimeout(100);assert.ok(true);console.log("test case end");});});
the expected output is
before start
before end
beforeEach start
beforeEach end
test case start
test case end
afterEach start
afterEach end
after start
after end
instead of
before start
beforeEach start << "beforEach" strarts before "before end"
before end
beforeEach end
test case start
test case end
afterEach start
afterEach end
after start
after end
If the hooks are not async then the order is correct.
In earlier node version the await keyword helped before the hooks but in node 22.0.0 it doesn't work.
How often does it reproduce? Is there a required condition?
always
What is the expected behavior? Why is that the expected behavior?
the expected console log is
before start
before end
beforeEach start
beforeEach end
test case start
test case end
afterEach start
afterEach end
after start
after end
What do you see instead?
before start
beforeEach start << "beforEach" strarts before "before end"
before end
beforeEach end
test case start
test case end
afterEach start
afterEach end
after start
after end
Activity
MoLow commentedon May 2, 2024
thanks for the great reproduction. I have opened a PR with a fix
ert78gb commentedon May 2, 2024
thx for the quick fix