Skip to content
This repository has been archived by the owner on Mar 5, 2022. It is now read-only.

Commit

Permalink
feat: add react-scripts plugins as alias to cra-v3
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Apr 30, 2020
1 parent 9efdec5 commit e4e4b6c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,19 @@ npm install --save-dev cypress cypress-react-unit-test
require('cypress-react-unit-test/support')
```

2. Tell Cypress how your React application is transpiled or bundled (using Webpack), so Cypress can load your components. See [Recipes](./docs/recipes.md)
2. Tell Cypress how your React application is transpiled or bundled (using Webpack), so Cypress can load your components. For example, if you use `react-scripts` do:

```js
// cypress/plugins/index.js
module.exports = (on, config) => {
require('cypress-react-unit-test/plugins/react-scripts')(on, config)
// IMPORTANT to return the config object
// with the any changed environment variables
return config
}
```

See [Recipes](./docs/recipes.md) for more examples.

3. ⚠️ Turn the experimental component support on in your `cypress.json`. You can also specify where component spec files are located. For example, to have them located in `src` folder use:

Expand Down
4 changes: 3 additions & 1 deletion docs/recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ If you are using Create-React-App v3 or `react-scripts`, and want to reuse the b
```js
// cypress/plugins/index.js
module.exports = (on, config) => {
require('cypress-react-unit-test/plugins/cra-v3')(on, config)
require('cypress-react-unit-test/plugins/react-scripts')(on, config)
// IMPORTANT to return the config object
// with the any changed environment variables
return config
Expand All @@ -27,6 +27,8 @@ module.exports = (on, config) => {

See example repo [bahmutov/try-cra-with-unit-test](https://github.com/bahmutov/try-cra-with-unit-test)

**Tip:** `plugins/react-scripts` is just loading `plugins/cra-v3`.

## Your webpack config

If you have your own webpack config, you can use included plugins file to load it.
Expand Down
9 changes: 9 additions & 0 deletions plugins/react-scripts/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const filePreprocessor = require('../cra-v3/file-preprocessor')

module.exports = (on, config) => {
require('@cypress/code-coverage/task')(on, config)
on('file:preprocessor', filePreprocessor(config))
// IMPORTANT to return the config object
// with the any changed environment variables
return config
}

0 comments on commit e4e4b6c

Please sign in to comment.