I use karma, webpack and jasmine to test my ES6 code, with istanbul and isparta to cover the code. My tests all seem to pass, but the reach is really low because I had to import jquery and jquery-resizable-dom, which are included in the coverage as unverified code.
I have a lot of vanilla js code (~ 200 lines), but then added something like this:
import $ from 'jquery';
require('imports?jQuery=jquery!jquery-resizable-dom');
const makeImagesResizable = () => {
$('.img').resizable({
handleSelector: '> .glyphicon-resize-full'
});
};
export { makeImagesResizable };
And in my jasmine test, I imported makeImagesResizableto test it. When I run the test, I get something like 27% code coverage because it includes jquery code in scope. Removing all the code above (importing jQuery and all code using jquery) will increase the reach to 94%, which is closer to the actual reach (the jquery code is quite short).
Is there a way to exclude third party imports from the code coverage to reflect the numbers we actually get from the code?
Here is my karma configuration:
const webpack = require('webpack');
const isparta = require('isparta');
module.exports = (config) => {
config.set({
frameworks: ['jasmine'],
files: [
'./spec/*.spec.js',
],
webpack: {
module: {
loaders: [
{ test: /\.js$/, loader: 'imports?define=>false!babel' },
],
},
},
webpackMiddleware: {
noInfo: true,
},
preprocessors: {
'./spec/*.spec.js': ['webpack', 'coverage'],
},
reporters: ['progress', 'coverage'],
coverageReporter: {
instrumenters: { isparta },
reporters: [
{
type: 'html',
dir: 'coverage',
},
],
},
browsers: ['Chrome'],
plugins: [
'karma-webpack',
'karma-jasmine',
'karma-coverage',
'karma-chrome-launcher',
],
});
};
I have included only test files, as including the source files for some reason do not return any coverage.