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

Commit ade6c83

Browse files
authored
feat: insert istanbul babel plugin in more situations (#253)
to get code coverage
1 parent 266ca85 commit ade6c83

File tree

8 files changed

+280
-8
lines changed

8 files changed

+280
-8
lines changed

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,14 @@ Keep your eye on issue [#156](https://github.com/bahmutov/cypress-react-unit-tes
299299

300300
</details>
301301

302+
<details id="missing-code-coverage">
303+
304+
If you are using your custom Webpack, this plugin might be missing code coverage information because the code was not instrumented. We try to insert the `babel-plugin-istanbul` plugin automatically, but your bundling might not use Babel, or configure it differently, preventing plugin insertion. Please let us know by opening an issue with full reproducible details.
305+
306+
See related issue [#141](https://github.com/bahmutov/cypress-react-unit-test/issues/141). You can also debug the plugin's behavior by running it with `DEBUG` environment variable, see [#debugging](#debugging) section.
307+
308+
</details>
309+
302310
## Development
303311

304312
See [docs/development.md](./docs/development.md)
@@ -311,6 +319,12 @@ You can see verbose logs from this plugin by running with environment variable
311319
DEBUG=cypress-react-unit-test
312320
```
313321

322+
Because finding and modifying Webpack settings while running this plugin is done by [find-webpack](https://github.com/bahmutov/find-webpack) module, you might want to enable its debug messages too.
323+
324+
```
325+
DEBUG=cypress-react-unit-test,find-webpack
326+
```
327+
314328
## Migration guide
315329

316330
### From v3 to v4

circle.yml

+7
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ workflows:
109109
working_directory: examples/sass-and-ts
110110
command: npm test
111111
store_artifacts: true
112+
post-steps:
113+
- run:
114+
name: Check coverage 📈
115+
command: |
116+
npm run check-coverage
117+
npm run only-covered
118+
working_directory: examples/sass-and-ts
112119

113120
- cypress/run:
114121
name: Visual Sudoku

examples/sass-and-ts/cypress.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
"componentFolder": "src",
88
"nodeVersion": "system",
99
"env": {
10-
"coverage": false
10+
"coverage": true
1111
}
1212
}

examples/sass-and-ts/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"private": true,
55
"scripts": {
66
"test": "../../node_modules/.bin/cypress run",
7-
"cy:open": "../../node_modules/.bin/cypress open"
7+
"cy:open": "../../node_modules/.bin/cypress open",
8+
"check-coverage": "../../node_modules/.bin/check-coverage src/App.tsx",
9+
"only-covered": "../../node_modules/.bin/only-covered src/App.tsx"
810
},
911
"devDependencies": {
1012
"cypress-react-unit-test": "file:../.."

examples/sass-and-ts/webpack.config.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ module.exports = {
1313
loader: 'babel-loader',
1414
options: {
1515
presets: ['@babel/preset-env', '@babel/preset-react'],
16-
plugins: ['@babel/plugin-proposal-class-properties'],
16+
plugins: [
17+
'@babel/plugin-proposal-class-properties',
18+
// we want to instrument unit tests on the fly so we usually insert this plugin
19+
// 'babel-plugin-istanbul',
20+
// but cypress-react-unit-test inserts this plugin automatically
21+
// if the code coverage is enabled, so you don't have to worry
22+
],
1723
},
1824
},
1925
{

0 commit comments

Comments
 (0)