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

Commit fd67ac7

Browse files
committed
point plugins at index file
1 parent a16c802 commit fd67ac7

File tree

1 file changed

+18
-36
lines changed

1 file changed

+18
-36
lines changed

docs/recipes.md

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,48 +13,38 @@ But usually you want to point Cypress at your application's current Webpack conf
1313

1414
## React Scripts
1515

16-
If you are using Create-React-App v3 or `react-scripts`, and want to reuse the built in webpack before ejecting, this module ships with Cypress preprocessor in [plugins](plugins) folder. From the `cypress.json` point at the shipped plugin in the `node_modules`.
16+
If you are using Create-React-App v3 or `react-scripts`, and want to reuse the built in webpack before ejecting, this module ships with Cypress preprocessor in [plugins](plugins) folder.
1717

18-
```json
19-
{
20-
"pluginsFile": "node_modules/cypress-react-unit-test/plugins/cra-v3",
21-
"supportFile": "node_modules/cypress-react-unit-test/support",
22-
"experimentalComponentTesting": true
18+
```js
19+
// cypress/plugins/index.js
20+
module.exports = (on, config) => {
21+
require('cypress-react-unit-test/plugins/cra-v3')(on, config)
22+
// IMPORTANT to return the config object
23+
// with the any changed environment variables
24+
return config
2325
}
2426
```
2527

26-
See example repo [bahmutov/try-cra-with-unit-test](https://github.com/bahmutov/try-cra-with-unit-test), typical full config with specs and source files in `src` folder (before [ejecting the app](https://github.com/bahmutov/cypress-react-unit-test/issues/134)):
28+
See example repo [bahmutov/try-cra-with-unit-test](https://github.com/bahmutov/try-cra-with-unit-test)
2729

28-
```json
29-
{
30-
"fixturesFolder": false,
31-
"pluginsFile": "node_modules/cypress-react-unit-test/plugins/cra-v3",
32-
"supportFile": "node_modules/cypress-react-unit-test/support",
33-
"testFiles": "**/*.spec.js",
34-
"experimentalComponentTesting": true,
35-
"componentFolder": "src"
36-
}
37-
```
30+
## Your webpack config
3831

39-
If you already have a plugins file, you can use a file preprocessor that points at CRA's webpack
32+
If you have your own webpack config, you can use included plugins file to load it.
4033

4134
```js
42-
// your project's Cypress plugin file
43-
const craFilePreprocessor = require('cypress-react-unit-test/plugins/cra-v3/file-preprocessor')
44-
module.exports = on => {
45-
on('file:preprocessor', craFilePreprocessor())
35+
// cypress/plugins/index.js
36+
module.exports = (on, config) => {
37+
require('cypress-react-unit-test/plugins/load-webpack')(on, config)
38+
// IMPORTANT to return the config object
39+
// with the any changed environment variables
40+
return config
4641
}
4742
```
4843

49-
**Bonus:** re-using the config means if you create your application using `create-react-app --typescript`, then TypeScript transpile just works out of the box. See [bahmutov/try-cra-app-typescript](https://github.com/bahmutov/try-cra-app-typescript).
50-
51-
## Your webpack config
52-
53-
If you have your own webpack config, you can use included plugins file to load it. Here is the configuration using the included plugins file and passing the name of the config file via `env` variable in the `cypress.json` file
44+
Pass the name of the config file via `env` variable in the `cypress.json` file
5445

5546
```json
5647
{
57-
"pluginsFile": "node_modules/cypress-react-unit-test/plugins/load-webpack",
5848
"experimentalComponentTesting": true,
5949
"env": {
6050
"webpackFilename": "demo/config/webpack.dev.js"
@@ -77,14 +67,6 @@ module.exports = (on, config) => {
7767
}
7868
```
7969

80-
In `cypress.json` file set:
81-
82-
```json
83-
{
84-
"experimentalComponentTesting": true
85-
}
86-
```
87-
8870
**Bonus:** in order to enable code instrumentation, add the `babel-plugin-istanbul` (included in this plugin) to your `.babelrc` setup. You can place it under `test` environment to avoid instrumenting production code. Example `.babelrc` config file that you can execute with `BABEL_ENV=test npx cypress open`
8971

9072
```json

0 commit comments

Comments
 (0)