-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fix: dont run all nested beforeAll hooks on test start #17938
base: main
Are you sure you want to change the base?
fix: dont run all nested beforeAll hooks on test start #17938
Conversation
@@ -1132,15 +1153,6 @@ pub const DescribeScope = struct { | |||
var i: TestRunner.Test.ID = 0; | |||
|
|||
if (this.shouldEvaluateScope()) { | |||
if (this.runCallback(globalObject, .beforeAll)) |err| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the main culprit, it goes up the parent chain and calls all beforeAll
blocks and its own before starting the test
@@ -1375,6 +1367,12 @@ pub const TestRunnerTask = struct { | |||
jsc_vm.onUnhandledRejectionCtx = this; | |||
jsc_vm.onUnhandledRejection = onUnhandledRejection; | |||
|
|||
if (this.describe.runCallback(globalThis, .beforeAll)) |err| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead we can trigger the beforeAll
blocks right before the beforeEach
blocks
Testing this manually, it seems there's some test failures in I also noticed a segfault running this test: beforeAll(() => {
throw new Error("oops");
});
test("t1", () => {
expect(1).toBe(1);
}); Not sure why it's happening, but seems the error printing is causing it. |
Ok will resolve |
What does this PR do?
This fixes a bug in the bun test runner related to
beforeAll
timing execution. Previously,beforeAll
blocks inside nesteddescribe
blocks would execute at the beginning of the entire test file, rather than immediately before theirdescribe
block began.Example test file:
Before fix:
After fix:
How did you verify your code works?
I updated the tests in
jest-hooks.test.ts
to validate this order of operationsbun-debug test test-file-name.test
)