Skip to content

Commit b8c7a6e

Browse files
authored
feat: add non .babelrc method (#48)
1 parent 5d829a9 commit b8c7a6e

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ module.exports = (on, config) => {
6666

6767
Now the code coverage from spec files will be combined with end-to-end coverage.
6868

69+
### Alternative
70+
71+
If you cannot use `.babelrc` for some reason (maybe it is used by other tools?), try pushing `babel-plugin-istanbul` directory to browserify plugins list.
72+
73+
```js
74+
module.exports = (on, config) => {
75+
on('task', require('@cypress/code-coverage/task'))
76+
on('file:preprocessor', require('@cypress/code-coverage/use-browserify-istanbul'))
77+
}
78+
```
79+
6980
## Instrument backend code
7081

7182
You can also instrument your server-side code and produce combined coverage report that covers both the backend and frontend code.

cypress/plugins/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ module.exports = (on, config) => {
55
// to get the code coverage from unit tests
66
// https://glebbahmutov.com/blog/combined-end-to-end-and-unit-test-coverage/
77
on('file:preprocessor', require('../../use-babelrc'))
8+
9+
// or use browserify and just push babel-plugin-istanbul
10+
// directory to the list of babelify plugins
11+
// on('file:preprocessor', require('../../use-browserify-istanbul'))
812
}

use-browserify-istanbul.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const browserify = require('@cypress/browserify-preprocessor')
2+
3+
const options = browserify.defaultOptions
4+
// transform[1][1] is "babelify"
5+
// so we just add our code instrumentation plugin to the list
6+
options.browserifyOptions.transform[1][1].plugins.push('babel-plugin-istanbul')
7+
module.exports = browserify(options)

0 commit comments

Comments
 (0)