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

Commit 3e12870

Browse files
committed
feat: add built-in code instrumentation
1 parent fbd07b1 commit 3e12870

File tree

5 files changed

+4805
-5251
lines changed

5 files changed

+4805
-5251
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,45 @@ If your React and React DOM libraries are installed in non-standard paths (think
133133

134134
How can we use features that require transpilation? By using [@cypress/webpack-preprocessor](https://github.com/cypress-io/cypress-webpack-preprocessor#readme) - see the plugin configuration in [cypress/plugins/index.js](cypress/plugins/index.js)
135135

136+
## Code coverage
137+
138+
If you are using [plugins/cra-v3](plugins/cra-v3) it instruments the code on the fly using `babel-plugin-istanbul`. If you want to disable the instrumentation, use `--env coverage=false` or `CYPRESS_coverage=false` or set in your `cypress.json` file
139+
140+
```json
141+
{
142+
"env": {
143+
"coverage": false
144+
}
145+
}
146+
```
147+
148+
Works really well with coverage reporting done by plugin [cypress-io/code-coverage](https://github.com/cypress-io/code-coverage).
149+
150+
### Create React App users
151+
152+
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`.
153+
154+
```json
155+
{
156+
"pluginsFile": "node_modules/cypress-react-unit-test/plugins/cra-v3",
157+
"supportFile": "node_modules/cypress-react-unit-test/support"
158+
}
159+
```
160+
161+
See example repo [bahmutov/try-cra-with-unit-test](https://github.com/bahmutov/try-cra-with-unit-test)
162+
163+
If you already have a plugins file, you can use a file preprocessor that points at CRA's webpack
164+
165+
```js
166+
// your project's Cypress plugin file
167+
const craFilePreprocessor = require('cypress-react-unit-test/plugins/cra-v3/file-preprocessor')
168+
module.exports = on => {
169+
on('file:preprocessor', craFilePreprocessor())
170+
}
171+
```
172+
173+
**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).
174+
136175
## Examples
137176

138177
All components are in [src](src) folder. All tests are in [cypress/integration](cypress/integration) folder.

0 commit comments

Comments
 (0)