karma-runner / karma-coverage

A Karma plugin. Generate code coverage.
MIT License
770 stars 247 forks source link

karma-coverage must be installed in order to run code coverage #426

Open sysmat opened 3 years ago

sysmat commented 3 years ago
"karma": "^5.2.3",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "^2.0.3",
    "karma-jasmine": "~4.0.1",
    "karma-jasmine-html-reporter": "^1.5.4",
    "karma-spec-reporter": "0.0.32",

and installed

dkimmich-onventis commented 3 years ago

I had the same issue after updating my project to Angular 11, and trying to set up karma-coverage.

Fixed it by adding the kjhtml reporter instead of the coverage reporter:

reporters: ['progress', 'kjhtml'],

Next time when you open such an issue, please give more context. With the little information you provided it is nearly impossible to help you.

sysmat commented 3 years ago

The same problem with angular 11

johnsonlin commented 3 years ago

Make sure you have it in plugins section: karma.conf.js

    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage'),  <--- add this line
      require('@angular-devkit/build-angular/plugins/karma'),
    ],

The official doc assumes that you know what you're doing and omits plugins section in the example I think. https://github.com/karma-runner/karma-coverage#basic image