简体   繁体   中英

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.

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

The right package to install to get rid of the above error is:

karma-coverage-istanbul-reporter

npm install karma-coverage-istanbul-reporter --save-dev

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM