Skip to content

Commit 09afa4c

Browse files
committed
feat: add babelrc helper script
1 parent fd6586f commit 09afa4c

File tree

5 files changed

+1131
-516
lines changed

5 files changed

+1131
-516
lines changed

README.md

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,43 +32,41 @@ If your application is loaded Istanbul-instrumented source code, then the covera
3232

3333
![Coverage report](images/coverage.jpg)
3434

35-
## Instrument unit tests
36-
37-
If you test your application code directly from `specs` you might want to instrument them and combine unit test code coverage with any end-to-end code coverage (from iframe). You can easily instrument spec files using [babel-plugin-istanbul](https://github.com/istanbuljs/babel-plugin-istanbul) for example. Put the following in `cypress/plugins/index.js` file to use `.babelrc` file
38-
39-
```js
40-
const browserify = require('@cypress/browserify-preprocessor')
35+
That should be it!
4136

42-
module.exports = (on, config) => {
43-
on('task', require('cypress-istanbul/task'))
37+
## Instrument unit tests
4438

45-
// tell Cypress to use .babelrc when bundling spec code
46-
const options = browserify.defaultOptions
47-
options.browserifyOptions.transform[1][1].babelrc = true
48-
on('file:preprocessor', browserify(options))
49-
}
50-
```
39+
If you test your application code directly from `specs` you might want to instrument them and combine unit test code coverage with any end-to-end code coverage (from iframe). You can easily instrument spec files using [babel-plugin-istanbul](https://github.com/istanbuljs/babel-plugin-istanbul) for example.
5140

5241
Install the plugin
5342

5443
```
5544
npm i -D babel-plugin-istanbul
5645
```
5746

58-
and set in your `.babelrc` file
47+
Set your `.babelrc` file
5948

6049
```rc
6150
{
6251
"plugins": ["istanbul"]
6352
}
6453
```
6554

55+
Put the following in `cypress/plugins/index.js` file to use `.babelrc` file
56+
57+
```js
58+
module.exports = (on, config) => {
59+
on('task', require('cypress-istanbul/task'))
60+
on('file:preprocessor', require('cypress-istanbul/use-babelrc'))
61+
}
62+
```
63+
6664
Now the code coverage from spec files will be combined with end-to-end coverage.
6765

6866
## Examples
6967

70-
- [Demo battery app](https://github.com/bahmutov/demo-battery-api/tree/bundle) branch "bundle"
7168
- Read ["Code Coverage by Parcel Bundler"](https://glebbahmutov.com/blog/code-coverage-by-parcel/) blog post
69+
- Read ["Combined End-to-end and Unit Test Coverage"](https://glebbahmutov.com/blog/combined-end-to-end-and-unit-test-coverage/)
7270

7371
## License
7472

cypress/plugins/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
module.exports = (on, config) => {
22
on('task', require('../../task'))
3+
4+
// also use .babelrc file when bundling spec files
5+
// to get the code coverage from unit tests
6+
// https://glebbahmutov.com/blog/combined-end-to-end-and-unit-test-coverage/
7+
on('file:preprocessor', require('../../use-babelrc'))
38
}

0 commit comments

Comments
 (0)