Nishant
Nishant

Reputation: 1044

Can not load reporter "coverage-istanbul"

I am trying to run code coverage using https://webpack.js.org/loaders/istanbul-instrumenter-loader/

Here is the karma.conf.js

var testWebpackCfg = require('../webpack/webpack.config.test.js');

module.exports = function(config) {
  config.set({
    basePath: '../../',
    frameworks: ['jasmine'],
    plugins: [ 'karma-webpack', 'karma-jasmine-jquery', 'karma-jasmine', 'karma-chrome-launcher','karma-firefox-launcher', 'karma-coverage','karma-spec-reporter', 'karma-jasmine-html-reporter'],

    preprocessors: {
      'client/test/index.js': ['webpack']
    },

    reporters: [ 'spec', 'coverage-istanbul'],

    coverageIstanbulReporter: {
      reports: [ 'text-summary' ],
      dir: './coverage',
      fixWebpackSourcePaths: true
    },

    files: [
      'client/test/index.js'
    ],

    webpack:  testWebpackCfg,

    // web server port
    port: 9876,
    runnerPort: 9100,
    urlRoot: '/',

    // level of logging
    // possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
    logLevel: config.LOG_INFO,


    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: false,

    browsers: ['Chrome'],
    singleRun: true
  });
};

Webpack config

{
            test: /\.js$/i,
            exclude: [
                paths.appNodeModules
            ],
            use: [
                {
                    loader: require.resolve('babel-loader'),
                    options: {
                        presets: ['@babel/preset-env']
                    }
                },
                {
                    loader: require.resolve('istanbul-instrumenter-loader'),
                    options: {
                        esModules: true
                    }
                }
            ]
        }

On running the Karma I see this error 'Can not load reporter "coverage-istanbul", it is not registered! Perhaps you are missing some plugin?'

Upvotes: 4

Views: 10167

Answers (3)

Tejas Savaliya
Tejas Savaliya

Reputation: 638

I faced the same problem after upgrading to Angular 14 from 11. Adding the Istanbul reporter compared to the Karma reporter solved my issue.

So simply add coverage-istanbul to your reporters in karma.conf.js

Like: reporters: ['progress', 'kjhtml', 'coverage-istanbul'],

For example:

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      ...
    ],
    client: {
     ...
    },
    coverageIstanbulReporter: {
      ...
    },
    reporters: ['progress', 'kjhtml', 'coverage-istanbul'],
})
}

Upvotes: 4

DJClayworth
DJClayworth

Reputation: 26886

Nishant gives the essential answer, but I found I also got this message when I had not specified the karma config file explicitly, as per this answer:

cant get junit running with Karma

Upvotes: 0

Nishant
Nishant

Reputation: 1044

The error got resolved by adding karma-coverage-istanbul-reporter in the karma config plugin.

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

karma.conf.js

{
    ...
    plugins: ['karma-coverage-istanbul-reporter']
    ...
}

Upvotes: 15

Related Questions