CRA is well known for bootstrapping a React App. It hides the complexity of bundling and configuration over react-scripts
. However, in some scenarios, it's very hard to customize CRA for a specific purpose. Make Jest Preview works seamlessly with CRA is an example.
Currently, there is no way to customize CRA's jest.config.js
file easily. So, Jest Preview bundles a few CLIs to make integrating Jest Preview to CRA effortless. We hope with this built-in helper CLI, CRA users can adopt Jest Preview easier.
Option 1 (Recommended): Use built-in codemod CLI:
- You just need to run the following command at the root of your CRA project:
npx jest-preview config-cra
or
./node_modules/.bin/jest-preview config-cra
Option 2: Configure manually
- Create
jest.config.js
with the following content:
Click to expand!
- Create test script at
scripts/test.js
Click to expand!
- Update test script in
package.json
{
"scripts": {
- "test": "react-scripts test"
+ "test": "node scripts/test.js"
}
}
After this, you've successfully configured step 3 and step 4 of Installation. Please follow Installation and Usage for more.
You can see the full example at Create React App Example.