react icon indicating copy to clipboard operation
react copied to clipboard

ReactDOM: Remove every test-util except `act()`

Open eps1lon opened this issue 1 year ago • 4 comments

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

eps1lon avatar Mar 11 '24 20:03 eps1lon

Comparing: 4cc0f8ee609068739308d03bac75b5d38f016f73...82e3562448dec7bc0319b9608563eac4f8ab41af

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js = 176.92 kB 176.92 kB = 54.99 kB 54.99 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 173.10 kB 173.10 kB = 53.94 kB 53.94 kB
facebook-www/ReactDOM-prod.classic.js = 592.31 kB 592.31 kB = 103.83 kB 103.83 kB
facebook-www/ReactDOM-prod.modern.js = 573.20 kB 573.20 kB = 100.71 kB 100.71 kB
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

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

react-sizebot avatar Mar 11 '24 20:03 react-sizebot

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.

jackpope avatar Mar 12 '24 14:03 jackpope

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.

eps1lon avatar Mar 13 '24 11:03 eps1lon

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

eps1lon avatar Mar 14 '24 14:03 eps1lon