-
-
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
beforeAll async hook hides errors #8688
Comments
Hi @iyobo, This issue is somewhat related to #8654. It's great that you've raised this issue, but I'd suggest changing the description a bit since it's not an accurate description of the actual problem. The actual problem is not that the error in ReproducibleYou can see a minimal reproducible version on top of the current beforeAll(async () => {
throw new Error('Error in beforeAll');
});
describe('tests', () => {
it('test 1', () => {
console.log('first: runs!');
});
it('test 2', () => {
console.log('second: runs!');
});
}); The behaviour in
|
@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. |
Hi @iyobo 😊, I see what you mean. I'm sorry if I'm misunderstanding the issue but I've tried the following (as per your description) and the failure didn't get swallowed (both in beforeAll(async () => {
throw new Error('Error in beforeAll');
});
it('first test', () => {}); Current log of the code above
Perhaps I'm missing something or I misunderstood what you meant? What exactly do you mean by being "swallowed"? Does it mean they are not shown at all? Again, sorry if I missed any details. Perhaps if you could share a reproducible and indicate which part of the output contains the desired behaviour we could debug this together? I've recently touched that part of the codebase so it's still fresh in my mind (which is why I jumped into this issue). |
I am seing the same, in my case occasionally, "swallowing" behaviour in my CI/CD tests,
I tried to reproduce this, but throwing an error or generating a timeout is printed just fine, both in my CI/CD environment and my local environment. The only difference I noticed is that when throwing an error myself (in this case generating a timeout) the error looks like this:
The error which is printing the mssage comes fron
The one that is not printing anything comes from
looking at the code there it seems like some optimisation was done there
|
@lucasfcosta I am wondering if it already breaks somewhere before the |
I do believe that the issue lies here. I am not sure why this error swapping is done, but just forwarding the original error gives me the correct underlying error message. I suppose that everything which does not adhere to the [isError](https://github.com/facebook/jest/blob/master/packages/jest-jasmine2/src/isError.ts check, e.g. a rejected promise, will actually be given out as an empty error message. |
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 |
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 It's possible to verify this by running The reason why this happened is that This has been fixed by adding a You can verify this by opening the 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 💖 |
Cool :-) I tried it by changing the jest-jasmine2 I also noticed that using |
workaround for jestjs/jest#8688
This is still unreleased/fixed. My dirty workaround: // setup-after-env.js
const _beforeEach = global.beforeEach;
global.beforeEach = fn => {
_beforeEach(async () => {
try {
await fn();
} catch (e) {
console.error(e);
throw e;
}
});
}; EDIT: my current workaround is to use mocha + earl 😆 |
The "dirty workaround" from above didn't work for me, but switching to circus runner did - https://github.com/facebook/jest/blob/master/packages/jest-circus/README.md. |
When you combine this issue with this one #2441 Things get real fun 🤨 |
Upgrading jest to the latest version fixed this issue for me (probably due to the new circus runner). |
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days. |
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one. |
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. |
🐛 Bug Report
The beforeAll hook hides errors.
To Reproduce
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:
The text was updated successfully, but these errors were encountered: