webpack
babel-istanbul instrumenter loader forInstrument Babel code with babel-istanbul for subsequent code coverage reporting.
Install
$ npm i babel-istanbul-loader --save-dev
Setup
References
Project structure
Let's say you have the following:
├── src/
│ └── components/
│ ├── bar/
│ │ └── index.js
│ └── foo/
│ └── index.js
└── test/
└── src/
└── components/
└── foo/
└── index.js
To create a code coverage report for all components (even for those for which you have no tests yet) you have to require all the 1) sources and 2) tests. Something like it's described in "alternative usage" of karma-webpack:
test/index.js
// require all `test/components/**/index.js`const testsContext = require; testsContext; // require all `src/components/**/index.js`const componentsContext = require; componentsContext;
This file will be the only entry point for Karma:
karma.conf.js
config;
Options
istanbul
– istanbul instrumenter options.
defaults:
embedSource: true noAutoWrap: true
cacheDirectory
+cacheIdentifier
– exactly the same cache options as in babel-loader.