dillon1000/react

Commit

Prefer JSX in ReactNoop assertions (to combat out-of-memory test runs) (#26127)

## Summary

Prefer `getChildrenAsJSX` or `toMatchRenderedOutput` over `getChildren`.
Use `dangerouslyGetChildren` if you really need to (e.g. for `toBe`
assertions).

Prefer `getPendingChildrenAsJSX` over `getPendingChildren`. Use
`dangerouslyGetPendingChildren` if you really need to (e.g. for `toBe`
assertions).

`ReactNoop.getChildren` contains the fibers as non-enumerable
properties. If you pass the children to `toEqual` and have a mismatch,
Jest performance is very poor (to the point of causing out-of-memory
crashes e.g.
https://app.circleci.com/pipelines/github/facebook/react/38084/workflows/02ca0cbb-bab4-4c19-8d7d-ada814eeebb9/jobs/624297/parallel-runs/5?filterBy=ALL&invite=true#step-106-27).
Mismatches can sometimes be intended e.g. on gated tests.

Instead, I converted almost all of the `toEqual` assertions to
`toMatchRenderedOutput` assertions or compare the JSX instead. For
ReactNoopPersistent we still use `getChildren` since we have assertions
on referential equality. `toMatchRenderedOutput` is more accurate in
some instances anyway. I highlighted some of those more accurate
assertions in review-comments.

## How did you test this change?

- [x] `CIRCLE_NODE_TOTAL=20 CIRCLE_NODE_INDEX=5 yarn test
-r=experimental --env=development --ci`: Can take up to 350s (and use up
to 7GB of memory) on `main` but 11s on this branch
- [x] No more slow `yarn test` parallel runs of `yarn_test` jobs (the
steps in these runs should take <1min but sometimes they take 3min and
end with OOM like
https://app.circleci.com/pipelines/github/facebook/react/38084/workflows/02ca0cbb-bab4-4c19-8d7d-ada814eeebb9/jobs/624258/parallel-runs/5?filterBy=ALL:
Looks good with a sample size of 1
https://app.circleci.com/pipelines/github/facebook/react/38110/workflows/745109a2-b86b-429f-8c01-9b23a245417a/jobs/624651
Browse files
Changed paths20 files
First-parent comparison
M packages/react-noop-renderer/src/ReactNoop.js ModifiedM packages/react-noop-renderer/src/ReactNoopPersistent.js ModifiedM packages/react-noop-renderer/src/createReactNoop.js ModifiedM packages/react-reconciler/src/__tests__/ReactExpiration-test.js ModifiedM packages/react-reconciler/src/__tests__/ReactFragment-test.js ModifiedM packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.js ModifiedM packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.internal.js ModifiedM packages/react-reconciler/src/__tests__/ReactIncrementalScheduling-test.js ModifiedM packages/react-reconciler/src/__tests__/ReactIncrementalSideEffects-test.js ModifiedM packages/react-reconciler/src/__tests__/ReactIncrementalTriangle-test.js ModifiedM packages/react-reconciler/src/__tests__/ReactIncrementalUpdates-test.js ModifiedM packages/react-reconciler/src/__tests__/ReactMemo-test.js ModifiedM packages/react-reconciler/src/__tests__/ReactNewContext-test.js ModifiedM packages/react-reconciler/src/__tests__/ReactNoopRendererAct-test.js ModifiedM packages/react-reconciler/src/__tests__/ReactPersistent-test.js ModifiedM packages/react-reconciler/src/__tests__/ReactSuspenseCallback-test.js ModifiedM packages/react-reconciler/src/__tests__/ReactSuspenseEffectsSemantics-test.js ModifiedM packages/react-reconciler/src/__tests__/ReactSuspenseFallback-test.js ModifiedM packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.js ModifiedM packages/react-reconciler/src/__tests__/useEffectEvent-test.js Modified
Patch

Files changed

Rendering syntax-highlighted changes…