-
-
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
Tests are run even when beforeAll throws error #2713
Comments
This is how jasmine behaves, I'm afraid this is a wontfix for now. |
btw cc @DmitriiAbramov who wants this changed. |
Is there any clean way to abort a test run other than |
@tamlyn do you mean |
No, I mean from within a test suite, I have a condition which means the rest of the file should not run so I want to skip all remaining tests or terminate the process or something. Like the behaviour which the OP expected when an exception is thrown in My specific use case is I'm writing some integration tests which hit the DB but I want don't want to run them if there's already data in there. |
@tamlyn oh. in this case i don't think there's a clean way of doing this. you can use |
Yes, exiting just one worker is what I want as they operate independently. It works with |
Problem with |
Ya, I agree. I have to say this is an astonishingly bad developer experience for cases that rely on complex setup procedures. We have several projects with integration tests that need to add fixtures to a real database, and this issue makes it very difficult to differentiate between setup errors and failed tests, especially since setup runs independently for each test file. It looks like this may be a better place to direct our comments, though. |
Is this going to be fixed, since both jasmine and mocha have this feature? And how should I use the beforeAll(() => {
mongoose.connect('mongodb://localhost/test').then(()=>{
mongoose.connection.dropDatabase('test')
}, err => {
process.exit
})
}) doesn't seem to work |
|
PR very much welcome porting the fix from Jasmine: jasmine/jasmine@585287b |
Wouldn't it be possible to imitate this behavior with |
Previously if the tests were run without first having run `yarn build`, these three test suites would fail with over 1000 lines of unclear console output. Now, later tests are stopped from running to reduce verbosity, and a more contributor-friendly error message displayed instead. We unfortunately can't handle this case in `beforeAll()`, since even if it throws, later tests in the same file are still run: jestjs/jest#2713
This is fixed in Jest circus, we won't be fixing it for Jasmine. If somebody sends a PR that's fine, but I'm going to close this as we won't get to it |
Sorry, what's the relation with jasmine here? For people who are not using jasmine, failures in |
@rattrayalex-stripe the old test runner for Jest (which is still currently the default) was powered by a jasmine fork called jest-jasmine2. We've written our own runner called jest-circus, which we're migrating everything to We fixed this issue in the jest-circus runner, and wont be fixing it in the jest-jasmine2 runner (my understanding is that it's a pretty tough one to fix in the jasmine runner) |
Ah, gotcha, thanks – guess if I'd been more patient on my request for a jest-circus readme I'd have found that out 😅 thanks @rickhanlonii ! |
Yup! Also see #6695 (comment) |
If you're looking for information about when Jest Circus is going to be released, see #6295. 🎪
In what version and PR was it fixed? I've tried installing |
I'm getting bit really hard by these issues: - jestjs/jest#2713 - jasmine/jasmine#577 - jasmine/jasmine#529
I'm getting bit really hard by these issues: - jestjs/jest#2713 - jasmine/jasmine#577 - jasmine/jasmine#529
…or (#12) Updates jest.config.js to recommend use of the jest-circus runner to enable tests to early-exit when beforeAll/beforeEach methods fail, per jestjs/jest#2713
It turns out that you can expect that behavior if:
I'm surprised and bummed that this behavior is not applied by default in Jest. |
With It's pretty surprising that there's a difference between:
and
I can understand why you would maybe want this behavior, but it would at least be nice if beforeAll() functions can check a flag like "are we actually going to run tests or have we already failed"? |
Seems like transitioning to jest-circus is ongoing: #6295 |
I couldn't test because I used Using |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
When beforeAll throws an error, or returns a Promise that rejects, the tests are still run. I would expect the tests to not even run at all.
See example repo:
https://github.com/dirkmc/jest-before-all-error-handling
And the output:
The text was updated successfully, but these errors were encountered: