BigW Consortium Gitlab

karma.config.js 2.5 KB
Newer Older
1
var path = require('path');
2
var webpack = require('webpack');
3 4 5
var webpackConfig = require('./webpack.config.js');
var ROOT_PATH = path.resolve(__dirname, '..');

6 7 8 9 10
// remove problematic plugins
if (webpackConfig.plugins) {
  webpackConfig.plugins = webpackConfig.plugins.filter(function (plugin) {
    return !(
      plugin instanceof webpack.optimize.CommonsChunkPlugin ||
11
      plugin instanceof webpack.optimize.ModuleConcatenationPlugin ||
12 13 14 15 16
      plugin instanceof webpack.DefinePlugin
    );
  });
}

17 18
webpackConfig.devtool = 'cheap-inline-source-map';

19 20
// Karma configuration
module.exports = function(config) {
21
  var progressReporter = process.env.CI ? 'mocha' : 'progress';
22 23

  var karmaConfig = {
24
    basePath: ROOT_PATH,
25
    browsers: ['ChromeHeadlessCustom'],
26
    customLaunchers: {
27
      ChromeHeadlessCustom: {
28
        base: 'ChromeHeadless',
29 30 31 32 33 34
        displayName: 'Chrome',
        flags: [
          // chrome cannot run in sandboxed mode inside a docker container unless it is run with
          // escalated kernel privileges (e.g. docker run --cap-add=CAP_SYS_ADMIN)
          '--no-sandbox',
        ],
35 36
      }
    },
37
    frameworks: ['jasmine'],
38
    files: [
39
      { pattern: 'spec/javascripts/test_bundle.js', watched: false },
40
      { pattern: 'spec/javascripts/fixtures/**/*@(.json|.html|.html.raw)', included: false },
41 42
    ],
    preprocessors: {
43
      'spec/javascripts/**/*.js': ['webpack', 'sourcemap'],
44
    },
45 46 47 48 49 50 51 52
    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 = {
53 54 55 56
      reports: ['html', 'text-summary'],
      dir: 'coverage-javascript/',
      subdir: '.',
      fixWebpackSourcePaths: true
57
    };
58
    karmaConfig.browserNoActivityTimeout = 60000; // 60 seconds
59 60
  }

61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
  if (process.env.DEBUG) {
    karmaConfig.logLevel = config.LOG_DEBUG;
    process.env.CHROME_LOG_FILE = process.env.CHROME_LOG_FILE || 'chrome_debug.log';
  }

  if (process.env.CHROME_LOG_FILE) {
    karmaConfig.customLaunchers.ChromeHeadlessCustom.flags.push('--enable-logging', '--v=1');
  }

  if (process.env.DEBUG) {
    karmaConfig.logLevel = config.LOG_DEBUG;
    process.env.CHROME_LOG_FILE = process.env.CHROME_LOG_FILE || 'chrome_debug.log';
  }

  if (process.env.CHROME_LOG_FILE) {
    karmaConfig.customLaunchers.ChromeHeadlessCustom.flags.push('--enable-logging', '--v=1');
  }

79
  config.set(karmaConfig);
80
};