-
-
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
JEST tests complete successfully but returns exit status 1 #9324
Comments
Repro please, or it didn't happen |
Hi @thymikee This happens in our repo and I am not able to create a reproducible sample repo. But what I could say is that the following command runs successfully,
whereas when running JEST cases via
jest.config.js
|
Can you try with |
I did a little more debugging and I could see that the exit code of the JEST execution (even when not run in
|
Anyway, without a repro there's nothing I can do. Please make sure you're on the latest version and try to come up with a minimal case by filtering out some tests until you get a correct exit code. |
I'm running into same issue, test passess successfully but jest returns status code 1 and npm errors.
Not sure if it's related but I'm using TypeScript and doing a async test with child processes and this seems so far to be the only case where I've encountered such behaviour. Though there seems to be no difference whether I'm running with ts-jest transform or directly against built js files. Oh and everything is updated to latest versions. |
As an update to this, it also seems to fail with Yarn
Same thing happens to me as for OP, if I run Jest directly from |
Same issue here, any solutions?
Edit: Upgrading node to latest version solved the issue for me |
Getting the same here pretty frequently when running in CI. It is intermittent but frequent enough to have started slowing things down.
|
Same issue here:
Did you guys find a solution? |
I'm seeing the same issue and now CI is failing all buddy builds. |
Also getting this on our CI (Codeship):
Here's the command being run:
Jest 25.2.7 We are upgrading from React Native 59 to 61 which has brought a new Jest version with it. I'm going to try downgrading back to Jest 24 and see if tests pass again. |
Same problem with yarn only v1.21.1 (jest v.25.2.3) |
i fixed it changing Solved: i needed to add |
I ran into this issue in two different ways while using ts-jest. I fixed both: 1.) I left a 2.) I was using a nyan cat jest reporter (because why not?), while also having type-specific errors. |
Got it. I had a couple of these:
which are probably down to bad mocks but I was just ignoring in previous versions of Jest. I narrowed down all my tests to a specific file and despite only 10 or so tests passing that log would appear and the tests would still exit with error. So I guess the tests should be failing because of this bad error, but maybe a specific jest error would be better than just exit 1! p.s. it was actually due to an old function using Promise.resolve().then() that was leaking out. The test was bad. I refactored to async/await and made sure the test was also async |
I was facing a similar issue using when I was running:
Which cause my tests to run, but the process was exiting with
Also, possibly there is a misleading await on my code which can cause this problem. 🤔 |
This was a face palm moment, I was digging around the tests and code trying to find some sign of why our CI test script was not running. Then it hit me. We are using snapshot tests and maybe the test suite could not run due to not being able to execute the snapshots. After adding -u to our npm run test:ci script, this resolved the issue. I leave this here in case this saves someone some time in considering that maybe the script cannot execute the snapshots. |
@smith-xyz you should never run Jest with |
@thymikee I was just looking at that and thinking the same thing after posting that comment. Is it best to only use snapshot tests outside of CI? |
You can use snapshots on CI as well, but they need to be written to disk/source control. When Jest runs next time (whether on dev machine or CI) it will recreate the snapshot and compare to the one that's supposed to be physically in the file system. The reason your CI may fail is because the files are not there (e.g. they were not added to source control, hence missing on CI). |
I get the same error:
|
I had the same problem, what worked for me was moving to an older build. I used jest@20.0.4 rather than current version
Let me know if this works! |
Yep downgrading to 20.0.4 worked for me as well. Current version worked fine from the command line, but when run via NPM I got the ELIFECYCLE error. There where no tests created yet. jest config from package.json
Node v14.3.0 |
|
I had a similar issue in my GH actions where all tests would pass but still exit 1.
It was all fine on my local machine. |
After 3 hours of messing around I ended up using this.
Happy to. Any criteria/preferred structure? I can make a repo with a repro if that suits you. |
Just chiming in with my organization's own issue with this on a Create React App instance. After upgrading to React 18.x, and upgrading Jest correspondingly, our test suite running on GitHub Actions began failing with a non-zero exit code despite passing all tests. We couldn't reproduce this locally, and were unable to get to the bottom of what the issue even was after hours of investigation. It wasn't even cleanly reproducible in CI: it usually failed this way, but not always. Given all of that, it might literally just be a GitHub Actions thing – but chiming in all the same. |
I've encountered the same variation as @shousper above #9324 (comment) We have two options to fix it:
|
npm i --save-dev jest npm ERR! A complete log of this run can be found in: |
Faced the same issue on GHA. Change the runner from |
Contrary to what I initially believed the issue does not seem to be in the Footer.test.tsx but in App.test.tsx . The error message appears after the Footer.test.tsx output and before the App.test.tsx output. The App test includes all components but was not checking for the footer content. My hypothesis is that when the test was done it tore down the msw handlers making the fetch request for config.json made in the Footer either abort or not be intercepted by msw. What set me on the right track was the following issue, in particular this comment jestjs/jest#9324 (comment) . Before this fix the tests would fail about once every 10 to 40 executions. After this fix the tests failed due to #561 after about 320 and after about 60 executions. There were no more failures because of this issue.
In my case the problem was that it was logging outside of the test suite. #10728 The message was logged but it was in the middle of all the execution so it was hard to see. |
New cause discovered today: TypeScript compilation errors aren't reported by |
In my case, it was just related to code coverage falling under the defined thresholds in jest config. In our case, I just lowered those thresholds to the actual values and everything worked fine. |
If you are using Node.js 20.x, ensure nothing in your tested code is setting the This makes any version of Jest fail, even when all tests are passing. This is being tracked here: #14501 |
#14501 got closed...? What's the work around here? We cannot set the |
#14619 may fix this for a number of people who are hitting errors during the coverage step that are being silently swallowed today. |
Thank you. This is the actual issue. Found some async methods called without awaiting and got the same error. Same test suite worked in older versions and got this error after upgrading node, jest, typeorm to latest. |
Summary: In Node 20, the script to run unit tests in CI (`scripts/run-ci-javascript-tests.js`) will fail, even when all the Jest tests pass. This happens because one of the JS modules being tested is setting `process.exitCode` (see jestjs/jest#9324 (comment)). Changes: - Modified the affected module to throw an exception when failing, instead of setting the exit code - Adjusted the unit test for that module ## Changelog: [General] [Fixed] - Remove setting of process.exitCode that breaks Jest tests Pull Request resolved: #45562 Test Plan: Before this change, running `node scripts/run-ci-javascript-tests.js` would fail with Node 20. After this change, it succeeds. Reviewed By: blakef Differential Revision: D60033582 Pulled By: cipolleschi fbshipit-source-id: 71b7f4495d414e719a9bd2d892bd1bc3045ddd5d
Summary: In Node 20, the script to run unit tests in CI (`scripts/run-ci-javascript-tests.js`) will fail, even when all the Jest tests pass. This happens because one of the JS modules being tested is setting `process.exitCode` (see jestjs/jest#9324 (comment)). Changes: - Modified the affected module to throw an exception when failing, instead of setting the exit code - Adjusted the unit test for that module ## Changelog: [General] [Fixed] - Remove setting of process.exitCode that breaks Jest tests Pull Request resolved: #45562 Test Plan: Before this change, running `node scripts/run-ci-javascript-tests.js` would fail with Node 20. After this change, it succeeds. Reviewed By: blakef Differential Revision: D60033582 Pulled By: cipolleschi fbshipit-source-id: 71b7f4495d414e719a9bd2d892bd1bc3045ddd5d
Summary: In Node 20, the script to run unit tests in CI (`scripts/run-ci-javascript-tests.js`) will fail, even when all the Jest tests pass. This happens because one of the JS modules being tested is setting `process.exitCode` (see jestjs/jest#9324 (comment)). Changes: - Modified the affected module to throw an exception when failing, instead of setting the exit code - Adjusted the unit test for that module ## Changelog: [General] [Fixed] - Remove setting of process.exitCode that breaks Jest tests Pull Request resolved: #45562 Test Plan: Before this change, running `node scripts/run-ci-javascript-tests.js` would fail with Node 20. After this change, it succeeds. Reviewed By: blakef Differential Revision: D60033582 Pulled By: cipolleschi fbshipit-source-id: 71b7f4495d414e719a9bd2d892bd1bc3045ddd5d
I had this issue and it was because there was a whole snapshot file that was no longer relevant as the accompanying tests had been deleted. Deleting that snapshot file fixed the problem. |
As many have written, the real source of the problem for us was these messages:
We'd been happily ignoring these for a long time, but then when we changed where our CI runner setup they suddenly starting making our jobs fail. Our quick fix to get the jobs passing again, also mentioned above, was to add |
I hit the same failure mode, but my issue was caused by #14501. That issue should be reopened as the issue still exists with Node 20.18 and Jest 29.7. |
I run JEST tests using
npm run test:jest
and the corresponding entry in package.json is"test:jest": "jest --config=./jest.config.js",
All tests run successfully, but returns with exit code 1
I am not sure why the process exits with status code 1 even though all tests pass.
The text was updated successfully, but these errors were encountered: