Weird coverage highlighting with istanbul-instrumenter-loader and Webpack
Hello all,
I may not be the only one to have wasted hours trying to figure out why the coverage report looked like this:
The reason was subtle:
You should have set the esModules
option of istanbul-instrumenter-loader to true. This option is not turned on by default as stated by Istanbul documentation. In order to make it work you should have your webpack.config.ts
file configured like this:
{
module: {
rules: [
{
test: /\.js$/,
exclude: /\.test.js$|\.spec.js$|node_modules/,
use: [
'babel-loader',
{
loader: 'istanbul-instrumenter-loader',
options: {
esModules: true
}
}
]
},
]
}
}
Please note that the order of the loaders is important! Istanbul loader should be put before babel-loader
.
The final result will now look like this:
It’s not a perfect coverage (that arrow function seems a bit weird) but it’s far better and something you can start working with.
Have a good day!
No comments yet.