Customizing Karma Reporters (JUnit, Cobertura, etc.) - mgechev/angular-seed GitHub Wiki

The seed.config.ts defines built-in Karma reporters. You can customize the reporters used by Karma by overriding the getKarmaReporters() method in your project.config.ts. (Obviously, any new reporter dependencies must first be installed via your package.json).

Some examples:

getKarmaReporters(): any {
  let result: any = super.getKarmaReporters();
  
  // Include JUnit-formatted test output (for Jenkins reporting, etc.):
  result.reporters.push('junit');
  result.junitReporter =  {
    outputDir: 'reports',
      outputFile: 'junit-test-results.xml',
      useBrowserName: false,
      suite: 'unit-test',
  };
  
  // Include Cobertura-formatted coverage output (for Jenkins reporting, etc.):
  result.coverageReporter.reporters.push(
    { type: 'cobertura', subdir: '.', file: 'cobertura-raw.xml' }
  );
  result.remapIstanbulReporter.reports.cobertura = this.COVERAGE_DIR + '/cobertura-coverage.xml';

  // Ignore skipped tests in Mocha console output:
  result.mochaReporter = {
    ignoreSkipped: true
  };
  
  return result;
}

Note: getKarmaReporters() is not used when running npm run test.watch! During test.watch, only the configuration specified in karma.conf.js is currently used. So if you're confused about why your customized reporters aren't running during test.watch, this is why.