question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

🐛 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  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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
SimenBcommented, Oct 20, 2018

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

1reaction
ciriascommented, Jul 20, 2018

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - jest hangs indefinitely, runs no tests - Stack Overflow
Your tests started 7 workers so it's hard to find exactly which one has an infinite loop. --runInBand CLI option it's good for...
Read more >
Why Jest freezes after tests run? (Jest hangs indefinitely)
If you noticed that Jest (npm / yarn) test hang at the end of the test execution while ... it forces Jest to...
Read more >
Troubleshooting - Jest
When Jest executes the test that contains the debugger statement, execution will pause and you can examine the current scope and call stack....
Read more >
How to Exit a Process in Node.js: process.exit() Method
Learn how to terminate a Node.js application in the best possible way. We will explain how to do this with the process.exit() function...
Read more >
Node.js v19.3.0 Documentation
If you need to use a callback-based API or your code assumes a custom thenable implementation, use the AsyncResource class to associate the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found