Fix reporting coverage when using babel.
If the istanbul-instrumenter-loader is added in a separate rule from the
babel-loader, the line numbers reported by coverage are wrong.
MODIFY
karma-base.js
karma-base.js
-var webpack_config = require('./webpack.config');
+var webpack_config = require('./webpack.base.config');
var url = require('url');
var fs = require('fs');
var path = require('path');

MODIFY
karma-cov.conf.js
karma-cov.conf.js
// Defines a test server for running jasmine unit tests
// with coverage support.
-var path = require('path');
-
/**
* Return URL friendly browser string
*/
@@ -40,11 +38,11 @@ module.exports = function (config) {
{type: 'text'}
]
};
- karma_config.webpack.module.rules.unshift({
- test: /\.js$/,
- include: path.resolve('src/'),
- exclude: path.resolve('src/polyfills.js'),
- use: ['istanbul-instrumenter-loader']
+ /* Alter our first webpack module rule which should just apply to src/*.js
+ * files. */
+ karma_config.webpack.module.rules[0].use.push({
+ loader: 'istanbul-instrumenter-loader',
+ options: {esModules: true}
});
config.set(karma_config);

MODIFY
webpack.base.config.js
webpack.base.config.js
@@ -75,12 +75,32 @@ module.exports = {
*/
module: {
rules: [{
+ /* The first rule only includes src/*.js so that it can conveniently be
+ * modified for istanbul instrumentation */
+ test: /\.js$/,
+ include: path.resolve('src'),
+ exclude: path.resolve('src/polyfills.js'),
+ use: [{
+ loader: 'babel-loader',
+ options: {
+ presets: [[
+ 'env', {
+ targets: {
+ browsers: ['defaults'],
+ uglify: true
+ },
+ useBuiltIns: 'usage'
+ }
+ ]],
+ cacheDirectory: true
+ }
+ }]
+ }, {
test: /\.js$/,
include: [
- path.resolve(__dirname, 'src'),
- path.resolve(__dirname, 'tests'),
- path.resolve(__dirname, 'examples'),
- path.resolve(__dirname, 'tutorials')
+ path.resolve('tests'),
+ path.resolve('examples'),
+ path.resolve('tutorials')
],
use: [{
loader: 'babel-loader',

Fix reporting coverage when using babel.

If the istanbul-instrumenter-loader is added in a separate rule from the
babel-loader, the line numbers reported by coverage are wrong.