I recently updated my jest package to the latest version from v24 and on running my unit tests, I am getting this at the end of test suite run:
A worker process has failed to exit gracefully and has been force exited.
This is likely caused by tests leaking due to improper teardown.
Try running with --runInBand --detectOpenHandles to find leaks.
I added --detectOpenHandles
with my test command and the messages goes in the next run. I am not sure how to take it as detectOpenHandles is intended for finding the open handles and not fixing it so how is the message not coming in next run and no other message to guide me on what could be the issue.
Has anyone came across similar bhaviour? To add, I am on latest version of jest i.e 27.2.0 now.
From my research, the error occurs when :
The error doesn't mention the fact that the tests will just hang most of the time even with --detectOpenHandles
flag, which is probably the reason why you aren't seeing any useful debugging messages.
From the documentation :
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.`
As it says in the documentation, you could try running the tests using the --detectOpenHandles
and the --forceExit
flag. This would mean the tests would run serially and each test would force exit when a test doesn't complete due to improper teardown. Let me know if this works.
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