RFC: Split Jest from React Native Core#926
Conversation
1891779 to
22e7083
Compare
| ## Alternatives | ||
|
|
||
| - **Continue including Jest:** We could continue including the preset, and take on the maintenance burden associated with this, as long as development and support is revilatised. | ||
| - **Switch default testing framework:** We could replace Jest with another test framework and runner like Vitest. However, this increases maintenance burden. | ||
| - **Minimal testing interface:** We could create a framework-agnostic unit testing interface. However, `@testing-library/react-native` already exists. | ||
|
|
||
| This proposal was chosen partially because options for E2E testing already exist, and alternative runners can use `@testing-library/react-native`. The main complexity of replacing Jest for React Native is associated with bundling. However, as new projects make strides in supporting more projects, as long as native-platform-extension support and Babel preset transpilation of all modules is possible, a test framework can start supporting React Native. Removing the `jest-preset` from `react-native` signals to contributors to encourage other test runners to support React Native, and encourages external maintenance of new test runners. |
There was a problem hiding this comment.
FWIW, @testing-library/* also runs in other systems. Like Bun: https://bun.com/guides/test/testing-library
Co-authored-by: Hassan Khan <contact@hassankhan.me>
| There are several key motivations for this change: | ||
|
|
||
| - **Maintenance Status:** While Jest 30 has now been released after a long break of major maintenance updates, [it includes a regression for `transformIgnorePatterns`](https://github.com/jestjs/jest/issues/15781), demonstrating that React Native isn't Jest's main focus, and that continuously maintaining a Jest preset in React Native that is part of the core package poses challenges. | ||
| - **Ecosystem Evolution:** Outside of Meta, many teams and projects have migrated to alternative testing solutions, especially for unit testing, such as Vitest. These days alternative test runners exist that are better set up to support React Native in the future, that the ecosystem signals they're starting to prefer. By bundling the Jest preset by default, we create an artificial constraint and recommendation that doesn't reflect current practices. |
There was a problem hiding this comment.
I agree and love this, but personally every time i have looked for setting up something like Vitest on React Native, the info out there is pretty minimal. Maybe also as part of this work we could also add some links to https://reactnative.dev/docs/testing-overview#writing-tests for Jest and alternatives?
|
|
||
| ## Unresolved questions | ||
|
|
||
| - Templates: Should templates include Jest generally, or not? |
There was a problem hiding this comment.
I would argue no, because a lot of people just use the template as is, and don't really setup tests at all, so keeping it around is just going to make them suffer through every jest upgrade (and while nowdays it is much easier, i do recall some pretty awful changes in older versions of Jest that basically resulted in us deciding keeping testing running was not worth the cost of not being able to upgrade RN)
Summary: This implements the proposal to split the Jest preset (and dependencies) out into a separate package: react-native-community/discussions-and-proposals#926 - `react-native` has an optional peer dependency on `react-native/jest-preset` - `react-native/jest-preset.js` throws when `react-native/jest-preset` isn't installed and instructs the user to add it to migrate - `react-native/jest-preset` may be used directly as a Jest preset ## Changelog: [General][Breaking] - Move Jest preset to new `react-native/jest-preset` package Pull Request resolved: #55169 Test Plan: The jest preset is used, with some modifications, in `facebook/react-native` itself and CI should confirm that the changes work. Running `jest` on the repo similarly validates that the preset still works. Otherwise, nothing has changed and the easiest way to test this is to use the preset in an existing project and try both `preset` set to the current value and `preset` set to `"react-native/jest-preset"` Reviewed By: cipolleschi Differential Revision: D91700684 Pulled By: huntie fbshipit-source-id: ee4a7d3ceb4934a3d0f7558d93dc601ea4b8dfa8
Proposal to remove
react-native/jest-presetin favour of a separate@react-native/jest-presetpackage.View the rendered RFC