I found a solution to this that does not involve losing coverage data!
Based on this guide for Debugging Karma Unit Tests, I came up with the following, which works in IntelliJ:
var sourcePreprocessors = 'coverage';
var isDebugMode = function () {
return process.argv.some(function (argument) {
return argument === '--debug';
});
};
var hasNoCoverage = function () {
return !(process.argv.some(function (argument) {
return argument.includes("coverage");
}));
};
if (isDebugMode() || hasNoCoverage()) {
console.log("Not generating coverage.");
sourcePreprocessors = '';
}
config.set({
...
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
"WebRoot/js/**/*.js": sourcePreprocessors
},
...
});
NOTE:
Per info mentioned here, adding the following to your karma.conf.js
(or however you are configuring Karma) should disable minification:
coverageReporter: {
instrumenterOptions: {
istanbul: { noCompact: true }
}
}
However, this does not remove the coverage data, and the source files still end up getting mangled up:
__cov_SNsw2QFfQtMZHyIEO9CT1A.s['74']++;
my.toPercentageString = function (value) {
__cov_SNsw2QFfQtMZHyIEO9CT1A.f['18']++;
__cov_SNsw2QFfQtMZHyIEO9CT1A.s['75']++;
return numbro(value).format('0.0%');
};
__cov_SNsw2QFfQtMZHyIEO9CT1A.s['76']++;