ReactDOM: Remove every test-util except `act()`
Summary
Removes every API from react-dom/test-utils except act in favor of using @testing-library/react. Removal is gated behind disableDOMTestUtils that's off for Meta builds.
The functions aren't removed but instead throw with a helpful error message. We're doing the same for ReactDOM.render.
Also reverts https://github.com/facebook/react/pull/28446 to restore test coverage.
Some APIs like renderIntoDocument are technically gated behind disableDOMTestUtils and disableLegacyRoot. We could just combine both flags to prevent drift.
How did you test this change?
-
yarn test ReactTestUtils-test
Comparing: 4cc0f8ee609068739308d03bac75b5d38f016f73...82e3562448dec7bc0319b9608563eac4f8ab41af
Critical size changes
Includes critical production bundles, as well as any change greater than 2%:
Significant size changes
Includes any change greater than 0.2%:
Expand to show
| Name | +/- | Base | Current | +/- gzip | Base gzip | Current gzip |
|---|---|---|---|---|---|---|
| oss-experimental/react-dom/umd/react-dom-test-utils.production.min.js | = | 12.03 kB | 8.73 kB | = | 4.70 kB | 2.75 kB |
| oss-experimental/react-dom/cjs/react-dom-test-utils.production.min.js | = | 11.94 kB | 8.59 kB | = | 4.66 kB | 2.67 kB |
| oss-experimental/react-dom/cjs/react-dom-test-utils.production.js | = | 42.64 kB | 26.34 kB | = | 12.10 kB | 7.16 kB |
| oss-experimental/react-dom/umd/react-dom-test-utils.development.js | = | 47.41 kB | 28.06 kB | = | 13.09 kB | 7.34 kB |
| oss-experimental/react-dom/cjs/react-dom-test-utils.development.js | = | 44.63 kB | 26.38 kB | = | 12.87 kB | 7.19 kB |
| test_utils/ReactAllWarnings.js | Deleted | 65.07 kB | 0.00 kB | Deleted | 16.27 kB | 0.00 kB |
Generated by :no_entry_sign: dangerJS against 82e3562448dec7bc0319b9608563eac4f8ab41af
I looked into vendoring ReactTestUtils in WWW to avoiding needing additional gating here but it has too much internal usage for it to be stable.
Can we apply either gating on the utils functions themselves or a build fork of the whole module? And additionally can we keep the ReactTestUtils-test with gating for www? Let me know if you want help with the additional work here.
Ideally within a couple months we can fully remove.
Can we apply either gating on the utils functions themselves or a build fork of the whole module?
We use special .fb entrypoints on other packages so I hope I can leverage these for test-utils and then just gate the tests behind www.
Didn't go with the special .fb entrypoint since that implies forking for modern, classic, experimental and stable. I used a simple feature flag instead like we do for ReactDOM.render