module.exports = function()

in config/karma.config.js [107:196]


module.exports = function(config) {
  process.env.TZ = 'Etc/UTC';

  const fixturesPath = `${IS_EE ? 'ee/' : ''}spec/javascripts/fixtures`;

  const karmaConfig = {
    basePath: ROOT_PATH,
    browsers: ['ChromeHeadlessCustom'],
    client: {
      color: !process.env.CI,
    },
    customLaunchers: {
      ChromeHeadlessCustom: {
        base: 'ChromeHeadless',
        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',
          // https://bugs.chromium.org/p/chromedriver/issues/detail?id=2870
          '--enable-features=NetworkService,NetworkServiceInProcess',
        ],
      },
    },
    frameworks: ['jasmine'],
    files: [
      { pattern: 'spec/javascripts/test_bundle.js', watched: false },
      { pattern: `${fixturesPath}/**/*@(.json|.html|.png|.bmpr|.pdf)`, included: false },
    ],
    preprocessors: {
      'spec/javascripts/**/*.js': ['webpack', 'sourcemap'],
      'ee/spec/javascripts/**/*.js': ['webpack', 'sourcemap'],
    },
    reporters: ['mocha'],
    webpack: webpackConfig,
    webpackMiddleware: { stats: 'errors-only' },
    plugins: [
      'karma-chrome-launcher',
      'karma-coverage-istanbul-reporter',
      'karma-jasmine',
      'karma-junit-reporter',
      'karma-mocha-reporter',
      'karma-sourcemap-loader',
      'karma-webpack',
    ],
  };

  if (process.env.CI) {
    karmaConfig.reporters.push('junit');
    karmaConfig.junitReporter = {
      outputFile: 'junit_karma.xml',
      useBrowserName: false,
    };
  } else {
    // ignore 404s in local environment because we are not fixing them and they bloat the log
    function ignore404() {
      return (request, response /* next */) => {
        response.writeHead(404);
        return response.end('NOT FOUND');
      };
    }

    karmaConfig.middleware = ['ignore-404'];
    karmaConfig.plugins.push({
      'middleware:ignore-404': ['factory', ignore404],
    });
  }

  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,
    };
    karmaConfig.browserNoActivityTimeout = 60000; // 60 seconds
  }

  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');
  }

  config.set(karmaConfig);
};