dom-testing-library: jest run reports "A worker process has failed to exit gracefully ..."
DOM Testing Libraryversion: 7.2.1nodeversion: 10.15.3npm(oryarn) version: 6.13.6
Relevant code or config:
require('@testing-library/dom');
What you did:
See above.
What happened:
Jest (?) is reporting the warning 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. at the end of a test run
Reproduction:
Probably pretty hard. See below.
Problem description:
The problem is that when we require('@testing-library/dom');. (even if we never call configure() or any other RTL code) at the end of the test run of 3500 tests we get the above warning. Trying to subdivide the tests to find the “offending test”, makes the problem go away. So, it isn’t directly due to some misbehaving test.
Interestingly, if we use require('@testing-library/react'); and do not directly import .../dom we don’t see the problem.
I’m not seriously expecting that you can fix this given the paucity of information I have to offer. And given that we’re on React 15, node 10 (though current Jest) it is entirely possible that this is a result of some older version of things that doesn’t happen on newer configurations. Instead, I’m filing this mainly to let you know this is happening, and to leave a record to allow others to know that someone else has seen this problem.
(the workaround appears to just be to not do any configuration of @testing-library/dom 😃
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 38
- Comments: 30 (4 by maintainers)
Commits related to this issue
- cannot fix strange bug, I believe this is a react problem, but its hard to say. Related: <https://github.com/testing-library/dom-testing-library/issues/524> — committed to DawsonReschke/web-sprint-challenge-intro-to-react by DawsonReschke 2 years ago
- v0.41.0 Update tests Added DOMPurify module for sanitizing user input for forms. Update vscode launch.json for debugging. Update `.gitignore` to ignore files prefixed with a single underscore for f... — committed to lgoodcode/whitelist by lgoodcode 2 years ago
- v0.41.0 Update tests Added DOMPurify module for sanitizing user input for forms. Update vscode launch.json for debugging. Update `.gitignore` to ignore files prefixed with a single underscore for f... — committed to lgoodcode/whitelist by lgoodcode 2 years ago
We also see this message.
jest --runInBand --detectOpenHandlesdoes not yield anything.Is there some way to identify which tests might be leaking?
so i only see this when i run the whole suite. in my test files, there are maybe 5 directories that contain all tests and running each one like
jest dir1andjest dir2yields no message, but running the full suite with simplejestdoes show the message. but when i run it with detectOpenHandles, the message goes away. am i going crazy?2 things that help me to troubleshoot this issue
setTimeOutfunctionMy problem was that I was trying to close an expressjs server but took time.
To solve the problems that are about timers, use
jest.useFakeTimers();I did face the same thing in 2021, A node v14.15.5 project. i did use jest 26.6.3 for my testing. Had only passed the --detectOpenHandles option, and Voila, the warning was gone.
We ran into this issue in our tests and it turned out to be someone using
waitFor()in their test.Ultimately, it seems like the cause is that RTL is configured to timeout tests at 1s (per this documentation) and Jest is configured to kill its workers after 500ms (see their source). Changing our default RTL config to timeout at less than 500ms fixed things for us.
@alexkrolick 👋
Yes, I should have mentioned I did try with the runInBand and detectOpenHandles. And “of course” the problem went away when I did that.
And the @testing-library/dom we’re getting is 7.2.1
🤷 Again, not asking for a fix, just recording that it happens.
I presume there’s another issue people are referring to here, but just incase someone finds themselves reading. For me deleting node modules and the yarn lock file then re installing dependencies resolved this issue 🤷🏻♂️
For anybody who gets here through search results, – try to check if you are really not forgetting to
.close()all your connections with databases, etc, – something that jest cannot figure out to close on its own. In my case, this was exactly that.This error suddenly appears today after having updated dependencies (no semver major updates) 🤔
If I rollback to previous dependency versions I don’t longer have the error 🤔
Edit: I don’t have React as dependency
Thanks @parzhitsky! It turns out I needed this for proper shutdown of the pg-promise resources:
Are you all running jest using a Mac? If so it may be related to https://github.com/facebook/jest/issues/10777 and fsevent bug https://github.com/fsevents/fsevents/issues/345 that has just been fixed 🤔
@omgoshjosh Not going crazy (well, maybe you are, that’s independent of this 😉 ). That’s exactly what I see too. I spent some time at one point pruning down the set of tests, hoping to isolate “the one bad test” causing this. but, as I recall eventually the problem seemed more a function of number of tests and it doesn’t seem tied to any individual test in any obvious way.
is the command suppose to be jest --runInBand --detectOpenHandles
You could try only running specific test files until you can isolate which ones are causing issues with open handles. If it’s many of them, you should check your setup scripts and test utilities.
Possibly, I’m not sure though. cc @romain-trotard
Could be a regression of #801 ? @kentcdodds
👋 Deej
This is tricky. Importing DTL/index is synchronous, so it shouldn’t really do anything that causes Promises or timeouts to leak… I assume your tried
Try running with --runInBand --detectOpenHandles to find leaks.and it didn’t yield any useful info?The only kind of suspicious thing I can think of is that importing
screencould maintain a reference todocument.bodythat is tied to the JSDOM instance that was present when it was created. This was added in v6.11.0.