karma-coverage
karma-coverage copied to clipboard
Karma coverage does not show any data when using webpack + ES6
Hi
My config
module.exports = function(config) {
config.set({
browsers: ["ChromeCanary"],
coverageReporter: {
type: "html",
dir : "./docs/js-coverage"
},
files: [{
pattern: "test.bundle.js",
watched: false
}],
frameworks: ["jasmine"],
preprocessors: {
"src/main/webapp/**/*.js": "coverage",
"test.bundle.js": ["webpack"]
},
reporters: ["coverage", "dots"],
singleRun: false,
webpack: {
module: {
loaders: [{
test: /\.js/,
exclude: /node_modules/,
loader: "babel-loader?cacheDirectory&optional[]=runtime"
}]
},
watch: true
},
webpackServer: {
noInfo: true
}
});
};
test.bundle.js
var context = require.context("./src/main/webapp", true, /.+\.test\.js$/);
context.keys().forEach(context);
Tests run fine, HTML report is generated, but it contains no files in the list.
Thanks.
+1
I have the same problem. I thought I did something wrong, but whatever I try, it just comes up with zero files in the generated HTML. Is this a bug?
Edit: I fixed this by adding isparta preloaders to the webpack.module:
preLoaders: [
{ test: /\.js|jsx$/, exclude: /(src|node_modules)/, loaders: ['babel'] },
{ test: /\.js|jsx$/, include: /(src)/, loaders: ['isparta'] }
],
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
Hi, I found an alternative. Use Isparta loader in your karma conf file.
preLoaders: [
{
test: /^((?!spec).)*\.js$/,
include: path.resolve('src/'),
loader: 'isparta'
}
],
Don't forget to require karma-coverage and add it in preprocessors.
I hope it will help you.
should work with angular-cli +1
Same issue here +1
+1
To get this to work you need the sourcemaps from the es6 transpile to be read by the webpack sourcemap constructor and applied so that the sourcemap seen by the istanbul remapper refer back to the original sources. IMO that's a lot of work, better to just run the tests on the unbundled code for the purpose of coverage.
coverage sourcemap not work. only index.js.
no filelists, can you help me?
Was not able to get coverage information with webpack (2) and karma-coverage. Had to use both "istanbul-instrumenter-loader" as a webpack file loader for test run and "karma-coverage-istanbul-reporter" as coverage reporter and after couple of days of struggles it worked.