Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?'

like image 738
Nishant Avatar asked Dec 11 '22 01:12

Nishant


1 Answers

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']
    ...
}
like image 121
Nishant Avatar answered Apr 21 '23 07:04

Nishant