karma-runner - karma 报应中的错误报道

标签 karma-runner istanbul

我已经配置了我的 karma.conf.js 并启用了预处理,以获得有关我的测试代码覆盖率的报告。我已将此行添加到 preprocessors 部分。

preprocessors: {
  'public/js/app.js': ['coverage'],
  'public/js/filters.js': ['coverage'],
  'public/js/directives.js': ['coverage'],
  'public/js/services/*.js': ['coverage'],
  'public/js/controllers/*.js': ['coverage'],
},

我得到的是一份完全错误的报告。我知道我已经为每个模块和其中的功能编写了测试。但是覆盖率报告只正确显示了服务测试。

例如指令测试。我知道我已经写了一些测试,测试也会被执行。但报告显示我只测试了 36% 的代码行。

Coverage Report

这种奇怪行为的原因可能是什么?

更新:

我从 spec reporter 看到了这个输出:

Directives:
      bsTooltip:
          when the element was created:
                PASSED  - should call the popup function
      bsSwitchtext:
          when the model isBusy changes to true:
                PASSED  - should call the button method with loading
          when the model isBusy changes to false changes:
                PASSED  - should call the button method with loading

所以我认为我的测试会全部执行。

最佳答案

看起来 Angular 使用的 Typescript 和 Jasmine 有问题。为测试构建启用源映射似乎可以解决此问题。

我在 Angular 6.1 中启用了 source map,如下所示,

转到angular.json,在主项目中,找到test,并添加sourceMap:true,为测试运行启用source map .

要在 CLI 中启用它,请使用命令 --source-map--sm=true 运行

Github 问题链接

  1. Code coverage report issue with branch coverage (if path not taken)
  2. ng test --code-coverage in 6.1 improperly detecting branches

我有义务写下这个答案,因为我遇到了同样的问题,这是谷歌搜索的第一个问题。

关于karma-runner - karma 报应中的错误报道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19065792/

相关文章:

git - 如何运行 git pre-commit Hook 以强制暂存文件的测试覆盖率不会降低?

angular - 在 Visual Studio Code 中使用 Jest 调试 Angular 测试

javascript - 使用 AngularJS、Karma 和 Jasmine 在 JavaScript 中记录/转储数据?

karma-runner - karma 配置 - 包括其他配置文件

javascript - Mocha 测试用例的 Istanbul 尔覆盖率仅显示规范文件(测试文件)的覆盖率报告

javascript - 如何从 rspec 集成测试中获取 nyc/istanbul JavaScript 覆盖率

angularjs - Jasmine 测试中未声明的 Controller

angularjs - 使用 templateUrl 和 Jade 测试 Angular 指令

javascript - 通过 Istanbul 尔提高分支机构覆盖率

node.js - Istanbul 尔代码覆盖率 : how to ignore such lines?