无法使用Karma运行Coverage

Car*_*ren 30 javascript code-coverage karma-runner

我正试图用业力运行覆盖,我得到警告:WARN [preprocess]:无法加载"覆盖",它没有注册!

当我跑'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/'
    }

  });
};
Run Code Online (Sandbox Code Playgroud)

viv*_*cau 47

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

plugins: [
  'karma-jasmine',
  'karma-coverage',
  'karma-chrome-launcher',
  'karma-firefox-launcher',
],
Run Code Online (Sandbox Code Playgroud)

更新:
我在运行覆盖范围时遇到了另一个问题,由伊斯坦布尔引起,我的错误是

[覆盖]:[TypeError:无法设置未定义的'覆盖'属性]

看看伊斯坦布尔正在做什么,结果发现我的一些js单元文件的路径在预处理器中已经过时了.

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

    preprocessors : {
        '**/app/js/*/*.js' : 'coverage',
        '**/app/js/modules/*/*.js' : 'coverage',
        '**/app/js/services/*/*.js' : 'coverage'
    }, 
Run Code Online (Sandbox Code Playgroud)

  • 如果您正在运行全局安装的karma节点包,那么所有其他业力插件也必须全局安装; 如果您正在运行项目本地业力,则需要确保为您的项目本地安装其他业力插件.拥有本地业力插件并启动全局安装的业力将导致"业力覆盖" - 未注册的错误类型. (2认同)

Ric*_*ers 12

对于它的价值,这对我来说很好.安装时间:

npm install -g karma
npm install -g karma-coverage
Run Code Online (Sandbox Code Playgroud)

配置karma.config.js:

module.exports = function(config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine'],
    files: ['app.js','tests.js'],
    preprocessors: { 'app.js': 'coverage' },
    reporters: ['dots', 'coverage'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    captureTimeout: 60000,
    singleRun: false
  });
};
Run Code Online (Sandbox Code Playgroud)

运行karma start karma.config.js.


小智 10

对于那些使用grunt测试来运行业力测试的人,并且有覆盖插件未加载问题的问题.请将plugins设置添加到您的Gruntfiles.js karama任务中,即

// Test settings
karma: {
  unit: {
    configFile: 'test/karma.conf.js',
    singleRun: true,
    plugins:[
      'karma-jasmine',
      'karma-coverage',
      'karma-phantomjs-launcher'
    ],
  }
}
Run Code Online (Sandbox Code Playgroud)


Fra*_*rzi 5

无需全局安装的解决方案

安装karma-coverage

npm install --saved-dev karma-coverage
Run Code Online (Sandbox Code Playgroud)

然后编辑karma.conf.js并添加require('karma-coverage')到 的数组中plugins

npm install --saved-dev karma-coverage
Run Code Online (Sandbox Code Playgroud)