【问题标题】:Is there a way to exclude all files with 100% or at a threshold across the board from karma-coverage text reporter results?有没有办法从业力覆盖文本报告器结果中排除所有 100% 或阈值的文件?
【发布时间】:2021-07-17 11:24:22
【问题描述】:

这对我来说很挑剔,我知道,但我有一个大型 Angular 应用程序,其中许多文件被 100% 覆盖或非常接近它,我想排除这些结果,所以我可以处理我需要并且没有所有额外的噪音。

我不想按名称排除文件,因为如果它们发生更改,它们可能会低于 OK 阈值。

我的karma.conf.js(我知道我可能不需要某些插件,这是团队共享的文件):

// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage'),
      require('@angular-devkit/build-angular/plugins/karma')
    ],
    reporters: ['progress', 'coverage'],
    coverageReporter: {
      reporters: [
        {type: 'text'},
        {type: 'text-summary'},
      ]
    },
    browsers: ['ChromeHeadless'],
    preprocessors: {'**/*.ts': ['coverage']},
    restartOnFileChange: true,
  });
};

我将尝试在此处附上我的示例输出的屏幕截图,类型为:'text'coverageReporter:

我尝试搜索 SO 和 karma / karma-coverage 文档,但我只能找到专门按名称排除文件/路径或更新阈值,但后者似乎仅用于确定显示的颜色。谢谢~

编辑:由于每个目录只有一个文件,因此通过为目录及其下的一个文件打印数字来不重复数字也很有用。我想我可能只需要深入研究杂草并创建一个拉取请求或其他东西。

【问题讨论】:

    标签: unit-testing karma-jasmine code-coverage karma-runner karma-coverage


    【解决方案1】:

    为此,您可以生成 HTML 格式的覆盖率报告。在那里您可以选择根据代码覆盖率对文件进行排序。

    要启用此类报告,您必须在 karma 配置中更新 coverageReporter 属性 -

    coverageReporter: {
        includeAllSources: true,
        dir: 'coverage/',
        reporters: [
            {type: 'text'},
            {type: 'text-summary'},
            {type: 'html', subdir: 'html/'}
          ]
        },
    

    报告将在coverage/html 文件夹中生成。

    【讨论】:

    • 谢谢你的第二个建议,虽然不是我想要的:( - 我不认为文本报告器有办法
    猜你喜欢
    • 1970-01-01
    • 2015-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-02
    相关资源
    最近更新 更多