Having problems? want to contribute? join our community slack.
npm install --save-dev babel-plugin-istanbul
Add it to
.babelrc in test mode:
Optionally, use cross-env to set
It just works with Karma. First, make sure that the code is already transpiled by Babel (either using
karma-browserify). Then, simply set up karma-coverage according to the docs, but don’t add the
coverage preprocessor. This plugin has already instrumented your code, and Karma should pick it up automatically.
It has been tested with bemusic/bemuse project, which contains ~2400 statements.
mocha on node.js (through nyc)
nyc, which will collect all the coverage report.
babel-plugin-istanbul respects the
exclude configuration options from nyc,
but you also need to configure NYC not to instrument your code by adding these settings in your
"nyc":"sourceMap": false"instrument": false
You don't want to cover your test files as this will skew your coverage results. You can configure this by providing plugin options matching nyc's
If you don't provide options in your Babel config, the plugin will look for
include config under an
"nyc" key in
You can also use istanbul's ignore hints to specify specific lines of code to skip instrumenting.
By default, this plugin will pick up inline source maps and attach them to the instrumented code such that code coverage can be remapped back to the original source, even for multi-step build processes. This can be memory intensive. Set
useInlineSourceMaps to prevent this behavior.
If you're instrumenting code programatically, you can pass a source map explicitly.