node.js - 无法找到 Karma-coverage

标签 node.js karma-jasmine karma-coverage

我正在尝试向我的应用程序添加 karma 覆盖范围,但我不断收到消息“无法加载覆盖范围,它未注册!”

不过,我使用“npm install karma-coverage --save-dev”来确保 karma 本地安装在我的 node_modules 文件夹中。

我的缩写文件结构是:

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

包.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
    })
}

karma 没有像其他模块那样自动加载覆盖范围是没有意义的,但我决定手动将覆盖范围添加到插件中,看看是否能解决问题。

我在框架和文件之间的 karma.config.js 文件中添加了以下代码。

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

此更改给我一个稍微不同的错误,“找不到插件 karma-coverage,您是否忘记安装它?”但最终它说的是同一件事,它找不到覆盖插件。

我在这里错过了什么?

最佳答案

我不确定为什么会这样,但我成功了。

首先我删除了我的全局 karma 安装

> npm uninstall -g karma

接下来我全局安装了karma-cli

> npm install -g karma-cli

它运行良好。

关于node.js - 无法找到 Karma-coverage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32849689/

相关文章:

javascript - 带有业力的覆盖率报告以及 javascript 和 typescript src 文件的混合

angular - 为什么 Angular 单元测试没有测试此服务中的订阅内容?

javascript - 一行代码的单元测试

node.js - MongoDb + Mongoose QueryStream - 以下文档更改

使用 toHaveBeenCalled 进行 Angular Jasmine 测试

angularjs - Karma 中服务调用成功响应的代码覆盖率

karma-runner - Karma 代码覆盖率 - 总是 100%?

node.js - Nodejs - Nodejs 中是否存在类似于请求模块的模块?

node.js - 有没有一种方法可以使用 Electron 日志在Electron应用程序中的console.log中记录所有内容?

Angular2 Material 'md-icon' 不是 Karma/Jasmine 的已知元素