Unable to run Coverage with Karma Unable to run Coverage with Karma javascript javascript

Unable to run Coverage with Karma


I got the same [WARN] because the plugin 'karma-coverage' was not defined inside the plugins of the config, try to see if adding it fixes your warning, not sure if it will fix your full problem.

plugins: [  'karma-jasmine',  'karma-coverage',  'karma-chrome-launcher',  'karma-firefox-launcher',],

UPDATE:
I also had a different problem when running the coverage, caused by istanbul, my error was

[coverage]: [TypeError: Cannot set property 'covered' of undefined]

After having a look what istanbul was doing it turned out that the paths to some of my js unit files were outdated in the preprocessors.

It was doing some of the coverage reports but it was not generating deep coverage reports for all files hence the error. Once I fixed the paths it was all good.

    preprocessors : {        '**/app/js/*/*.js' : 'coverage',        '**/app/js/modules/*/*.js' : 'coverage',        '**/app/js/services/*/*.js' : 'coverage'    }, 


For what it's worth, this works fine for me. Installed with:

npm install -g karmanpm install -g karma-coverage

Config in karma.config.js:

module.exports = function(config) {  config.set({    basePath: '',    frameworks: ['jasmine'],    files: ['app.js','tests.js'],    preprocessors: { 'app.js': 'coverage' },    reporters: ['dots', 'coverage'],    port: 9876,    colors: true,    logLevel: config.LOG_INFO,    autoWatch: true,    browsers: ['Chrome'],    captureTimeout: 60000,    singleRun: false  });};

Run with karma start karma.config.js.


For those who are using grunt test to run the karma test, and have the problem of coverage plugin not loaded issue. Please add the plugins setting into your Gruntfiles.js karama task, i.e.

// Test settingskarma: {  unit: {    configFile: 'test/karma.conf.js',    singleRun: true,    plugins:[      'karma-jasmine',      'karma-coverage',      'karma-phantomjs-launcher'    ],  }}