The process.exit(1)
call triggered when running a globally-installed version of Jest results in odd test results - even when all tests pass, the process returns a non-zero exit code, and it's not immediately clear why.
When jest
is assigned to npm test
(which is a pretty common convention), you get:
Please run `npm install` to use the version of Jest intended for this project.
...
163 tests passed (163 total in 30 test suites, run time 3.292s)
npm ERR! Test failed. See above for more details.
There are no obvious details (the "Please run..." line doesn't look like an error message") and no failing tests, so debugging is awkward.
Recommendations
getJest
entirely. If people want to use a non-local version of Jest without running npm install
, I'm not sure why the package should care?console.warn
without affecting the exit code because the tests may still run without trouble, and the warning is sufficient indication that the output might not reflect exactly what the user intended.Error
to make debugging easier - Node's built-in error handling is much more explicit than console.error
followed by process.exit(1)
.process.exit(1)
immediately rather than waiting for all the tests to run - if it's not okay to run Jest globally when there's a missing locally-defined dependency, then it shouldn't run at all.Thank you for bringing this up and for the detailed description of the issue. To be honest, I have been upset about this stuff myself and it definitely makes Jest's test suite a little harder to deal with.
I also agree the way this is working currently does not make any sense if Jest still ends up running tests anyway. I'm sorry you wasted time on this.
Would you be willing to send a pull request?
My suggestion is as follows:
process.exit(1)
.process.on('exit', () => console.log(chalk.red('The error message ')))
so that we get a nice, red message at the end of a test run telling you that something is not quite as it should.It will allow people to use the wrong version of Jest (which isn't recommended, because there might be breaking changes) but it will still finish the test run properly and will print a message at the bottom. What do you think?
@cpojer That works for me, thanks for the quick response! Will submit the PR shortly
@mmcgahan @cpojer I'm seeing this non-fatal error when running Jest inside a child package within a yarn workspaces monorepo. Feels like maybe it's being shown in error because the way you look for jest
isn't dealing with packages being hoisted up to the monorepo root?
Most helpful comment
@mmcgahan @cpojer I'm seeing this non-fatal error when running Jest inside a child package within a yarn workspaces monorepo. Feels like maybe it's being shown in error because the way you look for
jest
isn't dealing with packages being hoisted up to the monorepo root?