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
After inside describe is not executed when the before has an error #50842
import{it,before,describe,after}from'node:test'import{expect}from'expect'import{mainDataSource}from'./config/sql/index.js'describe('failing test suite',()=>{before(async()=>{awaitmainDataSource.initialize()thrownewError('error')})after(async()=>{awaitmainDataSource.destroy()})it('should be ok',async()=>{expect(1).toBe(1)})})
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
Running the after inside the describe.
What do you see instead?
The after is not executed and the test will never finish because it's not able to close all open handles.
Additional information
Using the global before & after just works as intended
import{it,before,describe,after}from'node:test'import{expect}from'expect'import{mainDataSource}from'./config/sql/index.js'before(async()=>{awaitmainDataSource.initialize()thrownewError('error')})after(async()=>{awaitmainDataSource.destroy()})describe('failing test suite',()=>{it('should be ok',async()=>{expect(1).toBe(1)})})
@MoLow
I am running the same code with Mocha and Jest testing lib, they run the after() hook if before throws.
JEST
describe("test suite",()=>{beforeAll(()=>{console.log("called beofre All");thrownewError("error");});afterAll(()=>{console.log("called after All");});it("run test",()=>{expect(1).toBe(1);});});
output
console.log
called beofre All
at Object.log (test.js:3:13)
console.log
called after All
at Object.log (test.js:7:13)
FAIL ./test.js
test suite
✕ run test (1 ms)
● test suite › run test
error
2 |beforeAll(() => {
3 | console.log("called beofre All");> 4 | throw new Error("error");| ^
5 | });
6 |afterAll(() => {
7 | console.log("called after All");
at Object.<anonymous> (test.js:4:11)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 0.352 s
Ran all test suites.
Mocha
constassert=require("assert");describe("test suite",function(){before(()=>{console.log("called beofre All");thrownewError("error");});after(()=>{console.log("called after All");});describe("#indexOf()",function(){it("should return -1 when the value is not present",function(){assert.equal([1,2,3].indexOf(4),-1);});});});
output
test suite
called beofre All
1) "before all" hook in"test suite"
called after All
0 passing (3ms)
1 failing
1) test suite
"before all" hook in"test suite":
Error: error
at Context.<anonymous> (test.js:19:11)
at processImmediate (node:internal/timers:466:21)
Activity
pulkit-30 commentedon Nov 22, 2023
Hey @MoLow, please confirm this issue, if it's a bug I would love to open PR for this.
MoLow commentedon Nov 23, 2023
I would expect this to be the behavior, dont think it is a bug
jorenvandeweyer commentedon Nov 24, 2023
I'm a bit confused if this would be intended behaviour when in the global scope it behaves differently? @MoLow
pulkit-30 commentedon Dec 5, 2023
@MoLow
I am running the same code with Mocha and Jest testing lib, they run the
after()hook if before throws.JEST
output
console.log called beofre All at Object.log (test.js:3:13) console.log called after All at Object.log (test.js:7:13) FAIL ./test.js test suite ✕ run test (1 ms) ● test suite › run test error 2 | beforeAll(() => { 3 | console.log("called beofre All"); > 4 | throw new Error("error"); | ^ 5 | }); 6 | afterAll(() => { 7 | console.log("called after All"); at Object.<anonymous> (test.js:4:11) Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: 0.352 s Ran all test suites.Mocha
output
test_runner: fixed to run after hook if before throws an error
test_runner: fixed to run after hook if before throws an error
test_runner: fixed to run after hook if before throws an error