无法使用 Karma 运行 Coverage

2024-05-02

我正在尝试使用 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/'
    }

  });
};

我得到了相同的[警告],因为插件“karma-coverage”没有在配置的插件中定义,尝试查看添加它是否可以修复您的警告,不确定它是否可以解决您的完整问题。

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

UPDATE:
我在运行报道时也遇到了一个不同的问题,由伊斯坦布尔引起,我的错误是

[覆盖]:[类型错误:无法设置未定义的属性“覆盖”]

在查看了 istanbul 正在做什么之后,发现我的一些 js 单元文件的路径在预处理器.

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

    preprocessors : {
        '**/app/js/*/*.js' : 'coverage',
        '**/app/js/modules/*/*.js' : 'coverage',
        '**/app/js/services/*/*.js' : 'coverage'
    }, 
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法使用 Karma 运行 Coverage 的相关文章

随机推荐