enzymejs / enzyme

JavaScript Testing utilities for React
https://enzymejs.github.io/enzyme/
MIT License
19.96k stars 2.01k forks source link

Hanging open handle in node 16 #2550

Closed jpage-godaddy closed 2 years ago

jpage-godaddy commented 2 years ago

The enzyme-adapter-react-16 package appears to use the global Worker class and set up a MessagePort. Node 16 has a native global Worker class. When running mocha, the process never terminates. In debugging with wtfnode, the cause was an open MessagePort handle. Just importing the library seems to be enough to cause the hang; you don't even have to use the adapter.

To work around this, I figured out that if I set up jsdom beforehand and reassign global.Worker to window.Worker. That seems to resolve the problem.

enzyme-adapter-react-16 should more gracefully run within a node 16 environment.

Current behavior

Importing enzyme-adapter-react-16 in a unit test suite causes test runner process to hang (observed with mocha)

Expected behavior

Processes should not hang

Version

library version
enzyme 3.11.0
react 16.14.0
react-dom 16.14.0
react-test-renderer 16.14.0
adapter (below) 1.15.6

Adapter

jpage-godaddy commented 2 years ago

Never mind. The root cause is actually this:

https://github.com/facebook/react/issues/20756