【问题标题】:Karma-coverage not found: But, it is installed找不到业力覆盖:但是,它已安装
【发布时间】:2015-03-16 16:06:47
【问题描述】:

我使用本指南 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
  });
};

现在,在运行 karma 时,我收到错误

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,问题仍然存在(因为插件是在本地加载的,所以无论如何我都不应该需要插件部分......) .我希望你们中的某个人有一个想法...谢谢!

【问题讨论】:

  • 好吧,正如我所说,“插件的使用:['karma-mocha', 'karma-coverage', 'karma-chrome-launcher', 'karma-ie-launcher', ] “,不起作用...
  • 那么,对于插件部分,您有相同的错误还是不同的错误?您在安装过程中是否有任何警告?
  • 当我包含插件部分时,错误完全相同。有趣的是,Karma 能够加载除 karma-coverage 之外的所有插件。但是,所有插件都是通过相同的 package.json 文件安装的,没有任何错误。警告。顺便说一句:我在 OSX 上运行它,也许这在某种程度上确实很重要。编辑:我的插件部分如下所示:插件:['karma-jasmine','karma-coverage','karma-chrome-launcher','karma-coffee-preprocessor'],
  • 您有本地或全球业力安装吗?默认情况下,Karma 使用与其同级文件夹中的所有插件。

标签: angularjs macos karma-runner karma-coverage


【解决方案1】:

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

【讨论】:

  • 模块是在~/.npm 中还是实际上在node_modules 文件夹中?你只是手动删除它们吗?还是您使用npm prune 删除?谢谢!
  • 据我记得,我只是通过 rm -f %location 手动删除了它们。抱歉,我忘记了路径细节;但是它应该是我的主文件夹中某处的 node_modules。
【解决方案2】:

npm install -g karma-coverage 安装 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
  })
}

【讨论】:

  • npm install -g karma-coverage 也为我工作。
猜你喜欢
  • 2015-12-27
  • 1970-01-01
  • 2018-03-01
  • 2019-06-30
  • 1970-01-01
  • 1970-01-01
  • 2014-06-28
  • 1970-01-01
  • 2017-01-07
相关资源
最近更新 更多