I'm using jest
for testing, and in a few test scenarios I get the jest
message:
Jest did not exit one second after the test run has completed.
While taking Jest's recommendation to run with --detectOpenHandles
and ending up with hanging test process that never ends, I saw other online suggestions to add the --forceExit
option as well. Now the test ends and everything is ok.
It worths mentioning that all the tests are running properly and passing, with or without the --detectOpenHandles --forceExit
options.
I wonder if is that considered as best practice in such cases? or is it just serving me as a "first aid"? What are the side effects of doing so?
Cheers,
--detectOpenHandles Attempt to collect and print open handles preventing Jest from exiting cleanly. Use this in cases where you need to use --forceExit in order for Jest to exit to potentially track down the reason. This implies --runInBand , making tests run serially.
Even distribution of test suites across workers If you're running your test suites in parallel (enabled by default), jest will cache information about how long each of your test suites takes to run.
By default, Jest will run tests against all changed files since the last commit, but watch mode also exposes many options. By hitting the w key, you can see the different ways to operate Jest in watch mode. The options are dynamic, so it's worth playing around within watch mode to see what's available.
It's in the Jest documentation. Another way is to run tests in watch mode, jest --watch , and then press P to filter the tests by typing the test file name or T to run a single test name.
From the documentation, the detectOpenHandles
option is for:
Attempt to collect and print open handles preventing Jest from exiting cleanly. Use this in cases where you need to use --forceExit in order for Jest to exit to potentially track down the reason. This implies --runInBand, making tests run serially. Implemented using async_hooks, so it only works in Node 8 and newer. This option has a significant performance penalty and should only be used for debugging.
The forceExit
option should never be used as a best practice, the only time you have to use is because:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With