javascript - 无法使用 Karma 运行 Coverage

标签 javascript code-coverage karma-runner

我正在尝试使用 karma 运行覆盖,但收到警告:警告 [预处理]:无法加载“覆盖”,它未注册!

我以为我在运行“npm install -g karma-coverage --save-dev”时安装了覆盖

这是我的配置文件:

module.exports = function(config) {
      config.set({
        // base path, that will be used to resolve files and exclude
        basePath: '',

        frameworks: ['jasmine'],

        // list of files / patterns to load in the browser
        files: [
                bunch of files..
        ],

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

        // use dots reporter, as travis terminal does not support escaping sequences
        // possible values: 'dots', 'progress'
        // CLI --reporters progress
        reporters: ['progress', 'coverage'],

        junitReporter: {
          // will be resolved to basePath (in the same way as files/exclude patterns)
          outputFile: 'test-results.xml'
        },

        // web server port
        // CLI --port 9876
        port: 9876,

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

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

        // enable / disable watching file and executing tests whenever any file changes
        // CLI --auto-watch --no-auto-watch
        autoWatch: true,

        // Start these browsers, currently available:
        // - Chrome
        // - ChromeCanary
        // - Firefox
        // - Opera
        // - Safari (only Mac)
        // - PhantomJS
        // - IE (only Windows)
        // CLI --browsers Chrome,Firefox,Safari
        browsers: ['ChromeCanary'],

        // If browser does not capture in given timeout [ms], kill it
        // CLI --capture-timeout 5000
        captureTimeout: 20000,

        // Auto run tests on start (when browsers are captured) and exit
        // CLI --single-run --no-single-run
        singleRun: true,

        // report which specs are slower than 500ms
        // CLI --report-slower-than 500
        reportSlowerThan: 500,

        // compile coffee scripts
        preprocessors: {
            'someFileName': ['coverage'],
        },

        plugins: [
          'karma-jasmine',
          'karma-chrome-launcher',
          'karma-firefox-launcher',
        ],

    coverageReporter: {
        'type' : 'cobertura',
        'dir': 'coverage/'
    }

  });
};

最佳答案

我得到了相同的 [WARN],因为插件 'karma-coverage' 没有在配置的插件中定义,试着看看添加它是否能解决你的警告,不确定它是否能解决你的全部问题。

plugins: [
  'karma-jasmine',
  'karma-coverage',
  'karma-chrome-launcher',
  'karma-firefox-launcher',
],

更新:
我在运行覆盖时也遇到了不同的问题,由 Istanbul 尔引起,我的错误是

[coverage]: [TypeError: 无法设置未定义的属性 'covered']

在查看了 istanbul 的操作后,我发现我的一些 js 单元文件的路径在预处理器 中已过时。

它正在做一些覆盖率报告,但它没有为所有文件生成深度覆盖率报告,因此出现了错误。一旦我修复了路径,一切都很好。

    preprocessors : {
        '**/app/js/*/*.js' : 'coverage',
        '**/app/js/modules/*/*.js' : 'coverage',
        '**/app/js/services/*/*.js' : 'coverage'
    }, 

关于javascript - 无法使用 Karma 运行 Coverage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18069865/

相关文章:

javascript - 正则表达式获取两个字符之间的所有内容

javascript - 如何在服务器端将 Box2d 与 Node.js 结合使用

javascript - MVC3 中使用 ajax 进行 Webgrid 刷新

java - 如何在保持代码覆盖率的同时进行 Junit 测试和预期异常

python - 覆盖率显示 Django 测试的百分比太低

macos - 已安装 karma 时未找到 karma 命令

python:带有非默认参数的defaultdict

javascript - 使用 Karma 和 Jasmine 在 Angularjs 中以表单作为参数测试函数

javascript - 在 TypeScript 中声明 javascript 命名空间

code-coverage - TFS "code coverage"仪表板图表中未显示 TFS 2010 服务器构建代码覆盖率