jest: The cli doesn't exit correctly when stdout is a non-tty
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
If you are redirecting stdout to a file (or have stdout not connected to a tty in a similar way), then the jest-cli process will exit with 0 even if there are failing tests. If you execute jest from the cli without any kind of redirect in place, then you get a non-zero exit value for failing tests as expected.
It appears that this was introduced with the exit changes in this PR https://github.com/facebook/jest/pull/5313
What is the expected behavior?
A non-zero exit value in the case of test failures.
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
- node v6.11.4
- npm v3.10.10
- jest 22.1.1
- ubuntu 14.04
NOTE I updated the description since the original bug report with my latest findings
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 8
- Comments: 36 (12 by maintainers)
I can confirm we are experiencing the same issue, all great locally but on Jenkins a failed test run exits with
0
. Pinning bothjest
andjest-cli
to22.1.0
fixes it.Same issue with jenkins and jest 24.9.0
I’m using jest 24.9.0 and seeing the same issue, i’m not seeing exit code 1 with failure (i’m using AWS codebuild for CI) Anyone has the same issue anymore?
Thanks @szeller for the repro repository, it definitely helped tracking down the problem 🙂
I manually patched my
node_modules
folder with the proposed change in #5445 and looks like the message (exit is broken
) is not shown anymore when redirecting to a file.@markFromMST I think that’s potentially a different problem. For the one that I’m encountering, the failure count is always correct and the exit value is the only thing that is wrong
It looks like it’s due to the
exit
dependency attempting to write to stdout/stderr in combination with exit being called in aprocess.on('exit')
handler. The exit module will place the call toprocess.exit(exitCode)
on the event loop which will never run if the exit function was called via the ‘exit’ event.This should only happen on asynchronous stdout/stderr streams.
I made a test case repo for this one https://github.com/szeller/jest_failure_bug
In order to reproduce, you need to use AWS codebuild using the default node 6 build. Since there’s a failure in one of the tests, the build should fail (and does fail on jest 22.1.0) but won’t fail on jest latest