are there side effects of running jest with –detectOpenHandles –forceExit?
jest for testing, and in a few test scenarios I get the
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?
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.
forceExit option should never be used as a best practice, the only time you have to use is because:
- An async function did not finish
- A promise function did not finish
- A Websocket connection is still open
- A Database connection is still open
- Everything having a connect/disconnect methods did not disconnect before the end of the test