jest: beforeAll async hook hides errors
π Bug Report
The beforeAll hook hides errors.
To Reproduce
beforeAll(async () => {
throw new Error('Y U NO SHOW?!')
});
Expected behavior
Errors thrown in beforeAll hooks should be thrown and not get swallowed up. Such a failure should also kill further testing for that file/parallel process given that whatever failed in beforeAll would be crucial for continued testing of that parallel.
Run npx envinfo --preset jest
Paste the results here:
npx: installed 1 in 0.736s
System:
OS: macOS 10.14.1
CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Binaries:
Node: 12.6.0 - ~/.nvm/versions/node/v12.6.0/bin/node
npm: 6.9.0 - ~/.nvm/versions/node/v12.6.0/bin/npm
npmPackages:
jest: ^24.8.0 => 24.8.0
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 57
- Comments: 16 (8 by maintainers)
Commits related to this issue
- add reproducible for beforeAll not aborting further tests (#8688) — committed to lucasfcosta/jest by lucasfcosta 5 years ago
- catch errors in beforeAll workaround for https://github.com/facebook/jest/issues/8688 — committed to RedHatInsights/xjoin-search by jharting 5 years ago
@lucasfcosta No. The issue here is that the errors thrown in beforeAll are getting swallowed, particularly when using an async function.
They come in as hidden unhandled promise exceptions instead.
I want to actually see the error that gets thrown in beforeAll when Iβm using an async function as that would give an indicator as to the actual problem why the test parallel failed.
This is still unreleased/fixed. My dirty workaround:
EDIT: my current workaround is to use mocha + earl π
When you combine this issue with this one https://github.com/facebook/jest/issues/2441 Things get real fun
π€¨
I added a repo to reproduce this, its not only a beforeAll issue. Its a general issue with rejected promises https://github.com/philiiiiiipp/jest-async-beforeall-error
Upgrading jest to the latest version fixed this issue for me (probably due to the new circus runner).
Cool π
I tried it by changing the jest-jasmine2
ERROR_REGEXand now it shows perfectly fine. ( node v10.16.0 )I also noticed that using
jest-circusthis works too. Which, I guess makes sense since it replacesjest-jasmine2.Hi @philiiiiiipp, thanks for your reproducible, it was extremely helpful π
I managed to reproduce the error by running your example using Node v12.6 (as described by the issueβs author).
That error, however, only happens on Jest
v24.8, not in the current state of master.Itβs possible to verify this by running
yarn installandyarn testin your repo (which usesv24.8) and then running the same tests using the current version of master.The reason why this happened is that
_addMissingMessageToStackwould not combine themessagewith the stack due to thisregex.testcheck failing.This has been fixed by adding a
:?to the regex, here. Theifcondition for doing the replace also changed, but just changing theregexso that the test passes will be enough to fix this.You can verify this by opening the
node_modulesfile and changingjest-jasmine2/build/reporter.jsto use the same value that is in master forERROR_REGEXand then you will start seeing the promise rejection message.This happened 26 days ago, so thatβs why itβs not present in the last release.
Given the above I believe this issue can be closed.
Thanks again @philiiiiiipp for the reproducible π