dillon1000/react

Commit

Jest + test renderer helpers for concurrent mode (#13751)

* Jest + test renderer helpers for concurrent mode

Most of our concurrent React tests use the noop renderer. But most
of those tests don't test the renderer API, and could instead be
written with the test renderer. We should switch to using the test
renderer whenever possible, because that's what we expect product devs
and library authors to do. If test renderer is sufficient for writing
most React core tests, it should be sufficient for others, too. (The
converse isn't true but we should aim to dogfood test renderer as much
as possible.)

This PR adds a new package, jest-react (thanks @cpojer). I've moved
our existing Jest matchers into that package and added some new ones.

I'm not expecting to figure out the final API in this PR. My goal is
to land something good enough that we can start dogfooding in www.

TODO: Continue migrating Suspense tests, decide on better API names

* Add additional invariants to prevent common errors

- Errors if user attempts to flush when log of yields is not empty
- Throws if argument passed to toClearYields is not ReactTestRenderer

* Better method names

- toFlushAll -> toFlushAndYield
- toFlushAndYieldThrough ->
- toClearYields -> toHaveYielded

Also added toFlushWithoutYielding

* Fix jest-react exports

* Tweak README
Browse files
Changed paths15 files
First-parent comparison
A packages/jest-react/README.md AddedA packages/jest-react/index.js AddedA packages/jest-react/npm/index.js AddedA packages/jest-react/package.json AddedA packages/jest-react/src/JestReact.js AddedM packages/react-reconciler/src/__tests__/ErrorBoundaryReconciliation-test.internal.js ModifiedA packages/react-reconciler/src/__tests__/ReactSuspenseWithTestRenderer-test.internal.js AddedM packages/react-test-renderer/src/ReactTestRendererScheduling.js ModifiedM packages/react-test-renderer/src/__tests__/ReactTestRendererAsync-test.js ModifiedM packages/react/src/__tests__/ReactProfiler-test.internal.js ModifiedD scripts/jest/matchers/testRenderer.js DeletedM scripts/jest/setupTests.js ModifiedM scripts/jest/spec-equivalence-reporter/setupTests.js ModifiedM scripts/rollup/bundles.js ModifiedM scripts/rollup/validate/eslintignore Modified
Patch

Files changed

Rendering syntax-highlighted changes…