efarley
efarley

Reputation: 8651

Karma-coverage cannot be found

I am trying to add karma coverage to my application however I keep getting the message "Cannot load coverage, it is not registered!"

However I have used "npm install karma-coverage --save-dev" to ensure that karma is installed locally in my node_modules folder, which it is.

My abbreviated file structure is:

app/
    node_modules/
        karma/
        karma_coverage/ // Coverage is in fact installed, with the other karma modules, as far as I understand this means the plugin should be automatically found and added to the project.
    public/ // Application files go here.
    tests/
        controllers/ // contains controller tests
        coverage/ // Contains coverage results (I might not need this, I'm not sure yet).
        services/ // contains service tests
        karma.config.js

package.json

  "devDependencies": {
      "jasmine-core": "^2.3.4",
      "karma": "^0.13.10",
      "karma-chrome-launcher": "^0.2.0",
      "karma-coverage": "^0.5.2", // I swear it's installed...
      "karma-firefox-launcher": "^0.1.6",
      "karma-ie-launcher": "^0.2.0",
      "karma-jasmine": "^0.3.6",
      "karma-ng-html2js-preprocessor": "~0.1",
      "karma-requirejs": "^0.2.2",
      "karma-safari-launcher": "^0.1.1"
    }

karma.config.js:

// Karma configuration

module.exports = function(config) {
    config.set({

        // base path that will be used to resolve all patterns (eg. files, exclude)
        basePath: '../public/',


        // frameworks to use
        // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
        frameworks: ['jasmine'],


        // list of files / patterns to load in the browser
        files: [
          'js/lib/angular/angular.js',
          'js/*.js',
          'js/lib/*.js',
          'js/lib/angular/angular-ui-states.js',
          'modules/*/*Ctrl.js',
          '../tests/angular-mocks.js',
          '../tests/**/*.js'
        ],


        // list of files to exclude
        exclude: [
          'js/passport.js'
        ],


        // test results reporter to use
        // possible values: 'dots', 'progress', 'coverage'
        // available reporters: https://npmjs.org/browse/keyword/karma-reporter
        reporters: ['progress', 'coverage'],


        // preprocess matching files before serving them to the browser
        // available preprocessors: https://npmjs.org/browse/keyword/karma-               preprocessor
        preprocessors: {
          'modules/**/*.js': ['coverage'],
          'js/servicess.js': ['coverage']
        },


        // web server port
        port: 9876,


        // enable / disable colors in the output (reporters and logs)
        colors: true,


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


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


        // start these browsers
        // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
        browsers: ['Chrome', 'IE', 'Safari', 'Firefox'],


        // Continuous Integration mode
        // if true, Karma captures browsers, runs the tests and exits
        singleRun: false
    })
}

It doesn't make sense that karma isn't automatically loading coverage like the rest of the modules, but I decided to manually add coverage into the plugins to see if that resolved the problem.

I added the following code to the karma.config.js file between frameworks and files.

// pluguns to use
    plugins: [
        'karma',
        'karma-jasmine',
        'karma-coverage'
    ],

This change gives me a slightly different error, "Cannot find plugin karma-coverage, did you forget to install it?" but ultimately it's saying the same thing, it can't find the coverage plugin.

What am I missing here?

Upvotes: 3

Views: 11884

Answers (1)

efarley
efarley

Reputation: 8651

I'm not sure why this worked but I got it working.

First I deleted my global karma install

> npm uninstall -g karma

Next I installed karma-cli globally

> npm install -g karma-cli

And boom it worked fine.

Upvotes: 2

Related Questions