Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
19
rated 0 times [  24] [ 5]  / answers: 1 / hits: 19407  / 6 Years ago, thu, november 29, 2018, 12:00:00

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,


More From » tdd

 Answers
32

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:




  • 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


[#53013] Monday, November 26, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
briza

Total Points: 259
Total Questions: 94
Total Answers: 101

Location: Reunion
Member since Mon, Dec 28, 2020
4 Years ago
;