-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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: stop printing the same error for each individual test caused by beforeAll when it fails #13273
base: main
Are you sure you want to change the base?
Conversation
Exciting! I agree on skipping when a hook fails
Seems wrong - all 3 were skipped |
@SimenB In a matter of fact, it was my initial goal to set skip mode for all tests. But as it turns out, when all tests in a test suite are skipped, no error is printed, even though state has unhandled errors (like in afterAll hook).
So if we want to modify this behavior we'll have to edit source code that calls Should we pursue this solution? Or ignoring state errors when all tests fail is the desired behavior? |
That sounds like a bug - although fixing it might be a semver major change. We have a concept of |
We can still land this in the meantime of course - it's strictly an improvement even if not "perfect" |
Well yes, that's how state errors are handled in But the errors are ignored because all test suit is skipped. I can't seem to find what calls |
@SimenB Also, this is my first PR and it will be helpful to me if you told me if I should mention you each time I reply. |
That sounds weird - could you post a small sample test that behaves this way?
The PR will bubble up on my notifications list regardless of the ping. Doesn't hurt, tho 🙂 I don't necessarily get a notification if you push code tho, so feel free to ping when you push 🙂 |
Here you go: describe('test that a 3rd party API remains consistent', () => {
test.skip('API function 1', () => expect(1).toBe(1)); // skipped
test.skip('API function 2', () => expect(2).toBe(2)); // skipped
test.skip('API function 3', () => expect(3).toBe(3)); // skipped
afterAll(() => expect('login').toBe('successfull')); // fails, should report failure
}); afterAll hook should be reported failed, but because all tests are meant to be skipped, the output ignores it. So skipping all tests in beforeAll the same way won't print the error. It might be needed to be reported in another issue. |
@SimenB |
This PR is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
Hey, should I let this PR to close? |
Completely forgot about this PR, sorry! |
CI is failing - would you be able to take a look? Or is that waiting for #13273 (comment)? |
Yeah, it is. |
can we merge the PR if it is done? |
Hey, as I have replied to @SimenB, this PR is yet done. There is an still an unfinished discussion about the PR implementation that I'd like one of the project maintainers could review so I can complete this feature. Here's my last comment regarding the issue: #13273 (comment) |
This PR is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
@itaizelther I just bumped the issue this links, since I assume this is still in the works? |
Hey @thernstig, I suggest an experienced individual should point to the module that has to be refactored or take the PR to self . |
@SimenB is there a chance you have some guidance? |
Summary
Closes #9901
This is a continuation of @vldmrkl PR at #10004.
The call of addErrorToEachTestUnderDescribe is causing this bug:
https://github.com/facebook/jest/blob/264a116fd7e2bed4d3511fc85cf53226e7d9748a/packages/jest-circus/src/eventHandler.ts#L172-L174
This function adds an error to each of the tests under describe in which the failed beforeAll is. My currently proposed solution is changing this function operation to fail only one test and skip the rest, so that the error message should be printed once and all tests remain unrun.
These changes haven't broken any existing test in the project, and it looks like it is much less confusing comparing to the previous version, though I would like to get confirmation that this is the expected behaviour.
Test plan
Let's reuse the example from the issue description and see a new behavior that this bug fix provides.
Example:
New behavior:
This test is also added as an unit test on this PR.