-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
afterAll
isn't triggered if there is no test
at the same level
#3494
Comments
yep, the afterAll is not working as top level lifecycle hook, it works only as scoped lifecycle hook 🥲 import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from "bun:test";
beforeAll(() => {
console.log("lifecycle hook: beforeAll");
});
beforeEach(() => {
console.log("lifecycle hook: beforeEach");
});
afterAll(() => {
console.log("lifecycle hook: afterAll");
});
afterEach(() => {
console.log("lifecycle hook: afterEach");
});
describe("start testing", () => {
afterAll(() => {
console.log("lifecycle hook: afterAll scoped");
});
test("dummy", () => {
expect(1).toEqual(1);
});
});
bun test v0.6.12 (039bbc68)
lifecycle_hooks.spec.ts:
lifecycle hook: beforeAll
lifecycle hook: beforeEach
✓ start testing > dummy [0.04ms]
lifecycle hook: afterEach
lifecycle hook: afterAll scoped
1 pass
0 fail
1 expect() calls
Ran 1 tests across 1 files. 1 total [10.00ms] the top level "lifecycle hook: afterAll" is missing from the output |
Thank you for your comment! It misses even nested if there is no Note: Both import {
afterAll,
afterEach,
beforeAll,
beforeEach,
describe,
expect,
test,
} from "bun:test";
beforeAll(() => {
console.log("lifecycle hook: beforeAll");
});
beforeEach(() => {
console.log("lifecycle hook: beforeEach");
});
afterAll(() => {
console.log("lifecycle hook: afterAll");
});
afterEach(() => {
console.log("lifecycle hook: afterEach");
});
describe("start testing", () => {
beforeAll(() => {
console.log("lifecycle hook: beforeAll scoped");
});
afterAll(() => {
console.log("lifecycle hook: afterAll scoped");
});
describe("nest", () => {
test("dummy", () => {
expect(1).toEqual(1);
});
});
});
This pair of |
Is it in progress? I'm very interested in this issue. My tests get stucked after the first suite execution because of the lack of afterAll |
Confirmed that 0.7.0 fixed my original issue. Thank you so much! |
What version of Bun is running?
0.6.12
What platform is your computer?
Linux 5.15.90.1-microsoft-standard-WSL2 x86_64 unknown
What steps can reproduce the bug?
Run
bun test
with the test code below:What is the expected behavior?
Both
afterAll
are executed:Note: This is the Jest's behavior:
What do you see instead?
No
afterAll
without test at the same level:Additional information
The workaround is adding a
test
at the same level:The text was updated successfully, but these errors were encountered: