Jest: Test run of code running `process.exit(1)` with workers hangs indefinitely

Created on 20 Jul 2018  路  5Comments  路  Source: facebook/jest

馃悰 Bug Report

Test run of several test files with workers (i.e., not in band) sometimes hangs indefinitely if the code under test calls process#exit.

Demo note: y is an alias for yarn, and the code is found at https://github.com/theneva/jest-process-exit.

run that hangs

Here's the output with the diff from #6714 applied:

run with output regarding <code>process#exit</code> call from #6714

To Reproduce

Steps to reproduce the behavior:

  1. Have a test subject that calls process.exit(1)
  2. Have one file with a test running that code, and (at least) one other test file which does not run any code calling process#exit
  3. Run the test files using workers (that is, without --runInBand)
  4. Hope for the best: the test run will sometimes simply terminate (possibly due to invocation order). Example:

run that simply terminates

A run of only the test file with the failing test always terminates immediately after process#exit is called, and the same applies when running multiple test files in band.

Expected behavior

The test run should exit with an error message instead of continuing indefinitely.

Additionally, it would be great with feedback on why the test failed via something like @SimenB's PR https://github.com/facebook/jest/pull/6714.

Link to repl or repo (highly encouraged)

https://github.com/theneva/jest-process-exit is the smallest I could manage.

Run npx envinfo --preset jest

Paste the results here:

System:
  OS: macOS High Sierra 10.13.6
  CPU: x64 Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
Binaries:
  Node: 8.11.2 - ~/.nvm/versions/node/v8.11.2/bin/node
  Yarn: 1.7.0 - /usr/local/bin/yarn
  npm: 6.1.0 - ~/.nvm/versions/node/v8.11.2/bin/npm
npmPackages:
  jest: ^23.4.1 => 23.4.1
Bug Confirmed Help Wanted

All 5 comments

Found the same issue yesterday! https://github.com/cirias/hanging-jest

@mjesun thoughts on this one?

@theneva Would you mind patching #6815 locally (on your node_modules) and checking? This should be good enough, as process.exit (the real one) won't be exposed anymore :)

@mjesun with #6815 applied the tests pass consistently! Nice! :tada:

Covered by #6714 IMO. Easy enough for people to stub out process.exit if they don't want to exit. Maybe we want to update the message? Not sure

Was this page helpful?
0 / 5 - 0 ratings