Karma Code Coverage
See original GitHub issueHello,
I am trying to get code coverage to work with Webpack and Karma. I’m running into MANY difficulties which are preventing my company from accurately testing the JS code. Included below is my Karma config file.
var config = require('./gulp/config'),
karmaWebpack = require('karma-webpack'),
webpackConfig = require('./gulp/util/webpack-multi-config'),
path = require('path');
var testSrc = './scripts/tests/**/*.tests.js',
jsSrc = './scripts/**(!tests)/*.js';
var karmaConfig = {
frameworks: ['mocha', 'sinon-chai'],
files: [
testSrc,
jsSrc
],
preprocessors: {
testSrc: ['webpack'],
jsSrc: ['webpack', 'coverage']
},
webpack: webpackConfig('test'),
singleRun: 'true',
reporters: ['spec', 'coverage'],
browsers: ['Chrome'],
coverageReporter: {
reporters: [
{ type: 'text' },
{ type: 'text-summary' },
{ type: 'html', dir: './coverage' }
],
},
client: {
captureConsole: false
},
specReporter: {
showSpecTiming: true
},
reportSlowerThan: 25
};
karmaConfig.preprocessors[testSrc] = ['webpack'];
karmaConfig.preprocessors[jsSrc] = ['webpack', 'coverage'];
module.exports = function (config) {
config.set(karmaConfig);
}
If I don’t include the actual JS source files all the testing works out fine, but code coverage is extremely poor (it’s including Webpack garbage and jQuery as part of the coverage). If I include the source files, which is proper, I get an error:
Cannot find module "../modules/[module-name]"
at scripts/tests/modules/[module-name].tests.js
I don’t understand this error as the modules do exist there. It’s almost like Karma and Webpack can’t be used at the same time. You either have to choose to use Webpack and ES6 modules -OR- do front-end JS testing. Has anyone successfully done this? I’ve looked for months on this issue and tried posting several different places with no success.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6
Top GitHub Comments
Also sometimes I get the following error in my console:
I am also not sure what this error means.
same problem