I am having difficulty getting the correct code coverage numbers when trying to use a combination of webpack, isparta, jasmine and karma. The numbers at the end of a test run do not reflect the ES6 code correctly. However, the UI shows the correct ES6 file, with the correct highlighting, just not the correct numbers.
Here is a screenshot of what I am talking about.
Wrong Code Coverage Numbers:
The code and highlighting is correct, but the numbers are not. For example, the Statement number is completely off. I am assuming these numbers are coming from the transpiled code.
Here is my karma.config.js:
'use strict';
var conf = require('./gulp/conf');
var _ = require('lodash');
var wiredep = require('wiredep');
var webpackConfig = require('./webpack.config.js');
function listFiles() {
var wiredepOptions = _.extend({}, conf.wiredep, {
dependencies: true,
devDependencies: true
});
var dependencies = wiredep(wiredepOptions).js;
dependencies.push('test-context.js');
return dependencies;
}
module.exports = function(config) {
var configuration = {
files: listFiles(),
logLevel: 'WARN',
frameworks: ['jasmine'],
browsers : ['PhantomJS'],
plugins : [
'karma-phantomjs-launcher',
'karma-coverage',
'karma-jasmine',
'karma-webpack'
],
preprocessors: {
'test-context.js': ['webpack']
},
webpack: webpackConfig,
webpackMiddleware: {
noInfo: true
},
reporters: ['progress', 'coverage'],
coverageReporter: {
dir : 'coverage/',
reporters: [
{ type: 'html' }
]
}
};
config.set(configuration);
};
Here is my webpack config:
var webpack = require('webpack');
module.exports = {
node: {
fs: 'emtpy'
},
module: {
preLoaders: [
{
test: /\.js$/,
loader: 'isparta',
include: /(src)/
}
],
loaders: [
{
test: /\.js$/,
include: /(src)/,
loader: 'babel?stage=0'
}
]
},
resolve: {
extensions: [
'',
'.js'
]
},
devtool: 'inline-source-map'
};
Here is the test.context.js:
var context = require.context('./test', true, /\.js$/);
context.keys().forEach(context);
var srcContext = require.context('./src', true, /\.js$/);
srcContext.keys().forEach(srcContext);