JEST tests complete successfully but returns exit status 1
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
Test Suites: 1 skipped, 106 passed, 106 of 107 total
Tests: 10 skipped, 657 passed, 667 total
Snapshots: 14 files obsolete, 0 total
Time: 34.453s
Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @vc/[email protected] test:jest: `jest --config=./jest.config.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @vc/[email protected] test:jest script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/.npm/_logs/2019-12-18T13_01_11_869Z-debug.log
10 silly lifecycle @vc/[email protected]~test:jest: Args: [ '-c', 'jest --config=./jest.config.js' ]
11 silly lifecycle @vc/[email protected]~test:jest: Returned: code: 1 signal: null
12 info lifecycle @vc/[email protected]~test:jest: Failed to exec test:jest script
13 verbose stack Error: @vc/[email protected] test:jest: `jest --config=./jest.config.js`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack at emitTwo (events.js:126:13)
13 verbose stack at EventEmitter.emit (events.js:214:7)
13 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at emitTwo (events.js:126:13)
13 verbose stack at ChildProcess.emit (events.js:214:7)
13 verbose stack at maybeClose (internal/child_process.js:915:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
14 verbose pkgid @vc/[email protected]
15 verbose cwd /workspace/vc.src/vco/src/server/node
16 verbose Linux 3.13.0-163-generic
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "test:jest"
18 verbose node v8.17.0
19 verbose npm v6.13.4
20 error code ELIFECYCLE
21 error errno 1
22 error @vc/[email protected] test:jest: `jest --config=./jest.config.js`
22 error Exit status 1
23 error Failed at the @vc/[email protected] test:jest script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
I am not sure why the process exits with status code 1 even though all tests pass.
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,
node /workspace/vc/vco/src/server/node/node_modules/.bin/jest --config=./jest.config.js
<Runs all the tests successfully >
Test Suites: 1 skipped, 106 passed, 106 of 107 total
Tests: 10 skipped, 657 passed, 667 total
Snapshots: 15 files obsolete, 0 total
Time: 24.668s, estimated 33s
Ran all test suites.
whereas when running JEST cases via npm is failing.
$ npm run test:jest
<Runs all the tests successfully >
Test Suites: 1 skipped, 106 passed, 106 of 107 total
Tests: 10 skipped, 657 passed, 667 total
Snapshots: 19 files obsolete, 0 total
Time: 25.982s
Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @velocloud/[email protected] test:jest: `jest --config=./jest.config.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @velocloud/[email protected] test:jest script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/vagrant/.npm/_logs/2019-12-18T15_15_30_620Z-debug.log
jest.config.js
'use strict';
module.exports = {
"projects": [
{
name: "vc-core",
displayName: "Jest - VC services",
bail: false,
clearMocks: false,
collectCoverage: false,
collectCoverageFrom: [
'**/lib/sample/getSample.js'
],
coverageDirectory: "/test-output/coverage",
coverageReporters: [
"json",
"text-summary",
"cobertura"
],
reporters: [
"default",
"./common/VcTestReporter",
"jest-junit"
],
setupFilesAfterEnv: ["./common/setup.js"],
testEnvironment: "./common/VcTestEnv.js",
testMatch: [
"**/__tests__/**/*.js"
],
testPathIgnorePatterns: [
"__tests__/aws.js",
],
verbose: true,
}
]
};
Can you try with yarn as well then? Maybe it's an issue with npm itself, try upgrading Node
I did a little more debugging and I could see that the exit code of the JEST execution (even when not run in npm context) is 1.
$node /workspace/vc/vco/src/server/node/node_modules/.bin/jest --config=./jest.config.js
<Runs all the tests successfully >
Test Suites: 1 skipped, 106 passed, 106 of 107 total
Tests: 10 skipped, 657 passed, 667 total
Snapshots: 15 files obsolete, 0 total
Time: 24.668s, estimated 33s
Ran all test suites.
$ echo $?
1
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.
PASS src/test/restart.test.ts
√ restart (3438ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 5.298s, estimated 6s
npm ERR! code ELIFECYCLE
npm ERR! errno 1
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
PASS src/test/restart.test.ts
√ restart (711ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 2.478s
Ran all test suites.
error Command failed with exit code 1.
Same thing happens to me as for OP, if I run Jest directly from node_modules/.bin/jest it run through successfully but when ran as npm script it returns exit code 1. Happens with both v24.x and v25.x.
Same issue here, any solutions?
Test Suites: 1 passed, 1 total
--
24-Mar-2020 18:09:46 | Tests: 4 passed, 4 total
24-Mar-2020 18:09:46 | Snapshots: 1 obsolete, 1 passed, 1 total
24-Mar-2020 18:09:46 | Time: 4.2s
24-Mar-2020 18:09:46 | Ran all test suites.
24-Mar-2020 18:09:46 | npm ERR! code ELIFECYCLE
24-Mar-2020 18:09:46 | npm ERR! errno 1
24-Mar-2020 18:09:46 | npm ERR! @app/front@ test:ci: `jest --ci`
24-Mar-2020 18:09:46 | npm ERR! Exit status 1
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.
Test Suites: 2 skipped, 233 passed, 233 of 235 total
Tests: 25 skipped, 1009 passed, 1034 total
Snapshots: 1 passed, 1 total
Time: 721.58s
Ran all test suites.
error Command failed with exit code 1.
error Command failed with exit code 1.
error Command failed.
Exit code: 1
Same issue here:
Test Suites: 14 passed, 14 total
Tests: 61 passed, 61 total
Snapshots: 1 passed, 1 total
Time: 22.589s
Ran all test suites.
error Command failed with exit code 1.
Did you guys find a solution? Thanks!
I'm seeing the same issue and now CI is failing all buddy builds.
Also getting this on our CI (Codeship):
Test Suites: 277 passed, 277 total
Tests: 1577 passed, 1577 total
Snapshots: 206 passed, 206 total
Time: 185.986s
Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] testNoCache: `jest --no-cache "--maxWorkers=1"`
npm ERR! Exit status 1
Here's the command being run:
jest --no-cache "--maxWorkers=1"
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 --runInBand to --maxWorkers=2 but i dont know the reason why it was failing.
Solved: i needed to add await to fireEvent like await fireEvent.press(button);
I ran into this issue in two different ways while using ts-jest. I fixed both:
1.) I left a fit( in my test suite. This for whatever reason was claiming that I had a pending test (rather than skipped). This caused npm to exit with an error code as 1.
Solution: Removed the f that I accidentally left. This file was now fine and npm was exiting with exit code of 0.
2.) I was using a nyan cat jest reporter (because why not?), while also having type-specific errors.
Solution: I removed the nyan cat jest reporter and used the default reporter. This made the TypeScript related type errors show up. I specifically changed a tsconfig.json value (noImplicitAny: true) recently and had some errors but the nyan cat jest reporter was silencing these errors.
Got it. I had a couple of these:
ReferenceError: You are trying to `import` a file after the Jest environment has been torn down.
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:
jest --silent --runInBand --testPathPattern=index.spec\\.tsx$
Which cause my tests to run, but the process was exiting with exit code 1. However, changing this to:
jest --silent --maxWorkers=2 --testPathPattern=index.spec\\.tsx$
i fixed it changing
--runInBandto--maxWorkers=2but i dont know the reason why it was failing.Solved: i needed to add
awaittofireEventlikeawait fireEvent.press(button);
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 -u on CI. The generated snapshot may likely be wrong and your tests will still pass, giving you false sense of security.
@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: "jest": "^26.0.1",
Test Suites: 17 passed, 17 total
Tests: 57 passed, 57 total
Snapshots: 3 obsolete, 26 passed, 26 total
Time: 13.062 s
Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test: `jest`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
I had the same problem, what worked for me was moving to an older build.
I used [email protected] rather than current version
yarn add [email protected]
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
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
Node v14.3.0 NVM 0.35.3 TypeScript 3.9.3
Snapshots: 3 obsolete, 26 passed, 26 total
obsolete - are the cause of the error, after their removal, the error is gone.
I had a similar issue in my GH actions where all tests would pass but still exit 1.
Test Suites: 10 passed, 10 total
Tests: 38 passed, 38 total
Snapshots: 0 total
Time: 98.33s
Ran all test suites.
npm ERR! Test failed. See above for more details.
##[error]Process completed with exit code 1.
It was all fine on my local machine.
The only thing I found that was different was the machine the test was running on in GH Actions.
So I changed my GH action runs-on from ubuntu-latest to macos-latest and no more exit code 1 🎉
So I changed my GH action runs-on from ubuntu-latest to macos-latest and no more exit code 1 🎉
After 3 hours of messing around I ended up using this.
Anyway, without a repro there's nothing I can do
Happy to. Any criteria/preferred structure? I can make a repo with a repro if that suits you.
So I changed my GH action runs-on from ubuntu-latest to macos-latest and no more exit code 1
Same experience on an Azure Pipeline build.
Same Here
I've tested on:
yarn: 1.22.4
npm: 6.14.6
node: 10.16.3
node: 12.18.4
In All Variantes, I've got exit code 1:
command
./node_modules/.bin/jest --coverage
"jest": "^25.5.4",
"jest-expo": "^38.0.2",
although all test pass successfully:
Test Suites: 1 passed, 1 total
Tests: 10 passed, 10 total
Snapshots: 0 total
Time: 21.434s
We've got some random errors from react-native packages, I think that some child process return errors and jest process follow the error.
Errors:
ReferenceError: You are trying to `import` a file after the Jest environment has been torn down.
at parseErrorStack (node_modules/react-native/Libraries/Core/Devtools/parseErrorStack.js:52:26)
at Function.parse (node_modules/react-native/Libraries/YellowBox/Data/YellowBoxWarning.js:40:16)
at registerError (node_modules/react-native/Libraries/YellowBox/YellowBox.js:206:60)
at errorImpl (node_modules/react-native/Libraries/YellowBox/YellowBox.js:96:25)
at CustomConsole.Object..console.error (node_modules/react-native/Libraries/YellowBox/YellowBox.js:53:15)
https://github.com/facebook/jest/issues/6434#issuecomment-647589824
I am using
react-native-testing-libraryand what resolved this error for me was to simply make the callback of the test caseasynclikeit('your test case', () => {...})becomes:
it('your test case', async () => {...})
This worked for me