Jest: Jest should `process.exit(0|1)` after tests finish running

Created on 3 Mar 2017  ·  3Comments  ·  Source: facebook/jest


Do you want to request a feature or report a bug?
feature/bug

What is the current behavior?
If a library misbehaves and doesn't let the process exit, then the process hangs indefinitely, though all tests pass. It could be argued that these libraries may not even be misbehaving as there are some valid reasons to not let the process end naturally.

If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test.

What is the expected behavior?
Jest exits the process when all tests are completed and there's nothing more for Jest to test.

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
I don't think it is relevant, but here:

  • jest: v19.0.2
  • node: v7.7.1
  • npm: 4.1.2
  • yarn: 0.21.3
  • os: Linux 4.10.1-gentoo #4 SMP PREEMPT Wed Mar 1 14:47:04 EST 2017 x86_64 Intel(R) Core(TM) i5-4300U CPU @ 1.90GHz GenuineIntel GNU/Linux

Most helpful comment

The answer did not solve the issue...

All 3 comments

That's what --forceExit is for but it's an escape hatch. If Jest doesn't exit, it means you are not cleaning up properly after your tests (use afterAll).

The answer did not solve the issue...

@cpojer - could you shed some light on why this is considered an escape hatch, and not default behaviour?

My expectation would be that invoking Jest is for the sole purpose of running tests. Once all test blocks have resolved one way or another, and each after* block has been processed, what's the reason to assume that processes that outlive Jest should continue to run?

IMO, these should be killed by default. We have after* for neat clean-up/shutdown if needed, but I'd bet the majority of the time a hard exit wouldn't present any issues.

Was this page helpful?
0 / 5 - 0 ratings