Search code examples
angularunit-testingkarma-jasminekarma-coverage

Angular Unit testing : can't change the reporter of karma


I am trying to use the JUnit reporter with karma.

When I launch

$ ng test --watch=false --code-coverage

It always outputs me

10% building modules 1/1 modules 0 active01 06 2017 11:57:51.797:ERROR 
[reporter]: Can not load reporter "coverage-istanbul", it is not registered!

The problem is, in my karma.conf.json I have no reference to istanbul :

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular/cli'],
    plugins: [
      require('karma-jasmine'),
      // require('karma-chrome-launcher'),
      require('karma-phantomjs-launcher'),
      require('karma-junit-reporter'),
      require('karma-mocha-reporter'),
      require('@angular/cli/plugins/karma')
    ],
    files: [
      { pattern: './src/test.ts', watched: false }
    ],
    preprocessors: {
      './src/test.ts': ['@angular/cli']
    },
    mime: {
      'text/x-typescript': ['ts', 'tsx']
    },
    junitReporter: {
      outputDir: 'coverage', // results will be saved as $outputDir/$browserName.xml
      useBrowserName: false, // add browser name to report and classes names
      outputFile: 'test-report.xml', // if included, results will be saved as $outputDir/$browserName/$outputFile
    },
    angularCli: {
      config: './angular-cli.json',
      environment: 'dev'
    },
    reporters: config.angularCli && config.angularCli.codeCoverage ?
      ['mocha', 'junit'] :
      ['mocha'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: [
      'PhantomJS',
      // 'Chrome'
    ],
    singleRun: false
  });
};

Do you have any idea where it might come from ?

I also deleted all packages refering to istanbul in my package.json file, I also used npm prune just to be sure.


Solution

  • So I wrote an issue on the Angular CLI project and they told me that using the code coverage option automatically adds the istanbul package, no matter what you have set up. The command I use is now

    ng test --reporters=junit --watch=false || ECHO