未找到Karma覆盖范围:但是,它已安装

时间:2015-01-18 15:19:08

标签: angularjs macos karma-runner karma-coverage

我使用本指南http://karma-runner.github.io/0.8/config/coverage.html设置我的Karma-coverage插件。此外,它通过package.json文件在本地安装,如下所示:

{
    "name": "myApp",
    "version": "0.1.0",
    "devDependencies": {
        "karma-jasmine": "latest",
        "karma-coverage": "latest",
        "karma-coffee-preprocessor": "latest",
        "karma-chrome-launcher": "latest",
        "coffee-script": "latest"
    }
}

我的Karma.conf看起来像这样:

// Karma configuration
// Generated on Sun Dec 07 2014 15:51:07 GMT+0100 (CET)

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

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


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

    // list of files / patterns to load in the browser
    files: [
        'javascripts/vendor/jquery_211.js',
        'javascripts/vendor/angular.js',
        'javascripts/vendor/angular-route.js',
        'javascripts/vendor/angular-mocks.js',
        '../app/assets/javascripts/app.coffee',
        'javascripts/*.js',
        'test/controllers/*.js'
    ],


    // list of files to exclude
    exclude: [
    ],


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


    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['progress', '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'],


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

现在,在运行业力时,我收到错误

WARN [reporter]: Can not load "coverage", it is not registered!
  Perhaps you are missing some plugin?
INFO [karma]: Karma v0.12.28 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
WARN [preprocess]: Can not load "coverage", it is not registered!
  Perhaps you are missing some plugin?

没关系,如果我在karma.conf文件的插件部分中包含karma-coverage,问题保持不变(因为插件在本地加载,我不应该需要插件部分......) 。我希望你们中的某个人有个主意......谢谢!

2 个答案:

答案 0 :(得分:3)

此问题的解决方案是我在用户主文件夹中安装了几个node_modules。通过npm卸载这些模块和本地安装的模块后,我通过npm链接进行了干净的重新安装。这解决了我的问题!

答案 1 :(得分:3)

npm install -g karma-coverage安装业力报道,它会正常工作,但我不知道为什么。

// Karma configuration
// Generated on Tue Oct 13 2015 11:14:07 GMT+0800 (CST)

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

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


    // 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'
    ],


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


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

    coverageReporter:{
      type: 'html',
      dir: './coverage'
    },


    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['progress','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'],


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

相关问题