summaryrefslogtreecommitdiff
path: root/config/karma.config.js
diff options
context:
space:
mode:
authorMike Greiling <mgreiling@gitlab.com>2017-03-20 22:29:45 +0000
committerAlfredo Sumaran <alfredo@gitlab.com>2017-03-20 22:29:45 +0000
commitfde335bfb755e766e058b25c65cbc514df9b33f9 (patch)
treed829eaccef8913b269b2915f2d9ee615c1adaffe /config/karma.config.js
parentb26d4d2ac4cdf3a66e16918dae28d9b724557dd2 (diff)
downloadgitlab-ce-fde335bfb755e766e058b25c65cbc514df9b33f9.tar.gz
Only add frontend code coverage instrumentation when generating coverage report
Diffstat (limited to 'config/karma.config.js')
-rw-r--r--config/karma.config.js32
1 files changed, 14 insertions, 18 deletions
diff --git a/config/karma.config.js b/config/karma.config.js
index c1d3751d88f..eb082dd28bf 100644
--- a/config/karma.config.js
+++ b/config/karma.config.js
@@ -3,17 +3,6 @@ var webpack = require('webpack');
var webpackConfig = require('./webpack.config.js');
var ROOT_PATH = path.resolve(__dirname, '..');
-// add coverage instrumentation to babel config
-if (webpackConfig.module && webpackConfig.module.rules) {
- var babelConfig = webpackConfig.module.rules.find(function (rule) {
- return rule.loader === 'babel-loader';
- });
-
- babelConfig.options = babelConfig.options || {};
- babelConfig.options.plugins = babelConfig.options.plugins || [];
- babelConfig.options.plugins.push('istanbul');
-}
-
// remove problematic plugins
if (webpackConfig.plugins) {
webpackConfig.plugins = webpackConfig.plugins.filter(function (plugin) {
@@ -27,7 +16,8 @@ if (webpackConfig.plugins) {
// Karma configuration
module.exports = function(config) {
var progressReporter = process.env.CI ? 'mocha' : 'progress';
- config.set({
+
+ var karmaConfig = {
basePath: ROOT_PATH,
browsers: ['PhantomJS'],
frameworks: ['jasmine'],
@@ -38,14 +28,20 @@ module.exports = function(config) {
preprocessors: {
'spec/javascripts/**/*.js': ['webpack', 'sourcemap'],
},
- reporters: [progressReporter, 'coverage-istanbul'],
- coverageIstanbulReporter: {
+ reporters: [progressReporter],
+ webpack: webpackConfig,
+ webpackMiddleware: { stats: 'errors-only' },
+ };
+
+ if (process.env.BABEL_ENV === 'coverage' || process.env.NODE_ENV === 'coverage') {
+ karmaConfig.reporters.push('coverage-istanbul');
+ karmaConfig.coverageIstanbulReporter = {
reports: ['html', 'text-summary'],
dir: 'coverage-javascript/',
subdir: '.',
fixWebpackSourcePaths: true
- },
- webpack: webpackConfig,
- webpackMiddleware: { stats: 'errors-only' },
- });
+ };
+ }
+
+ config.set(karmaConfig);
};