业力中的错误报道报道

时间:2013-09-28 10:15:56

标签: karma-runner istanbul

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

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

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

更新

我从规范记者那里看到了这个输出:

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

所以我认为我的测试都将被执行。

3 个答案:

答案 0 :(得分:1)

看起来Angular使用的Typescript和Jasmine出现了问题。为测试版本启用源映射似乎可以解决此问题。

我在Angular 6.1中启用了源地图,如下所示,

转到angular.json并在主项目中找到test,然后添加sourceMap:true以启用测试运行的源映射。

要在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

由于我遇到相同的问题,我不得不写这个答案,这是Google搜索上的第一个问题。

答案 1 :(得分:0)

尝试在显示为未覆盖的其中一个点添加console.log('testing123');。如果在您运行测试时出现,您就会知道伊斯坦布尔出了问题。

但是我的猜测是你的配置有问题,而且那些测试没有在al上运行,或者测试没有像你想象的那样执行代码。

答案 2 :(得分:0)

尝试将预处理器中的内容更改为:

preprocessors: {
  '**/public/js/**/*.js': ['coverage']
},

除非我在预处理器对象中使用** / before director之前的特定语法,否则我无法使报告生效。

The karma-coverage documentation包括预处理器中列出的前面的** / before目录。

基于this SO answer.

相关问题