【问题标题】:Karma coverage always shows 100%业力覆盖率始终显示 100%
【发布时间】:2017-06-13 04:20:57
【问题描述】:

我的 karma.conf.js 文件如下所示:

// Karma configuration
// Generated on Tue Jun 11 2013 14:14:12 GMT+0100 (GMT Daylight Time)


// base path, that will be used to resolve files and exclude
basePath = '';


// list of files / patterns to load in the browser
files = [
    JASMINE,
    JASMINE_ADAPTER,
    '../Scripts/angular/angular.js',
    '../Scripts/angular/restangular/underscore-min.js',
    '../Scripts/angular/restangular/restangular-min.js',
    '../Scripts/angular/angular-*.js',
    '../Scripts/angular/angular-test/angular-*.js',
    '../Scripts/angular/angular-ui/*.js',
    '../Scripts/angular/angular-strap/*.js',
    '../Scripts/angular/angular-http-auth/*.js',
    '../uifw/scripts/ui-framework-angular.js',
    '../app/app.js',
    '../app/**/*.js',
    'unit/**/*.js'
];


// list of files to exclude
exclude = [
  '../Scripts/angular/angular-test/angular-scenario.js'
];

preprocessors = {
  '**/../app/**/*.js': 'coverage'
};



coverageReporter = {
    type: 'html',
    dir: 'coverage/'
};


// test results reporter to use
// possible values: 'dots', 'progress', 'junit'
reporters = ['progress', 'coverage'];


// web server port
port = 9876;


// cli runner port
runnerPort = 9100;


// enable / disable colors in the output (reporters and logs)
colors = true;


// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel = LOG_DEBUG;


// enable / disable watching file and executing tests whenever any file changes
autoWatch = true;


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


// If browser does not capture in given timeout [ms], kill it
captureTimeout = 60000;


// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun = false;

我的文件夹结构如下:

Root
 |__ App
 |__ Scripts
 |__ Tests
 |__ .... other folders

Karma.conf.js 位于测试文件夹内。 Karma start karma.conf.jtests 文件夹中运行。

我的测试运行并创建了一个覆盖率文件夹,但覆盖率始终显示为 100%。

我做错了什么?

编辑:

事实上,这是一个简单的答案。 preprocessors = { '**/../app/**/*.js': 'coverage' }; 不再需要以 ** 为前缀

this for more details

【问题讨论】:

    标签: angularjs code-coverage karma-runner


    【解决方案1】:

    使用 istanbul-instrumenter-loader 设置 webpack 让我走上了正轨。 { test: /\.ts/, include: helpers.root('src', 'app'), loader: 'istanbul-instrumenter-loader', enforce: 'post' }

    【讨论】:

      【解决方案2】:

      您需要设置ANGULAR_SCENARIO_ADAPTERKarma 不使用JASMINE_ADAPTER

      【讨论】:

      • 我认为您将单元测试与端到端测试混淆了。我的问题是关于单元测试。请参阅我的编辑以获取对我有用的答案。
      • 我有同样的问题,我认为这不是适配器的问题。 Jasmine 测试实际上正在执行,并且 Karma 确实使用了 jasmine 适配器。问题是覆盖率报告总是 100%。
      【解决方案3】:

      在我看来,您的问题似乎是您无法找到任何要为其生成覆盖范围的文件。您的报告确实说运行了 0/0 行、0/0 语句等等。

      我遇到了类似的问题,这是由于我使用小写字母而不是大写字母引起的,您似乎遇到了与您有一个名为“App”的文件夹相同的问题,但您在配置。看看你能不能写**/../App/**/*.js': 'coverage'

      我也不确定,但我认为你应该写 ../App/**/*.js': 'coverage' 而不是 **/../App/**/*.js': 'coverage'

      【讨论】:

        猜你喜欢
        • 2016-04-05
        • 2015-10-06
        • 2021-10-19
        • 2016-03-21
        • 1970-01-01
        • 2023-03-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多