ng test --code-coverage 不打印覆盖率详细信息

Posted

技术标签:

【中文标题】ng test --code-coverage 不打印覆盖率详细信息【英文标题】:ng test --code-coverage not printing coverage details 【发布时间】:2018-12-05 13:11:16 【问题描述】:

当我使用ng test --code-coverage 运行测试时,我得到的代码覆盖率是未知的,不知道可能出了什么问题。感谢您提供任何帮助。

> ng test --code-coverage

 10% building modules 1/1 modules 0 active26 06 2018 11:00:51.088:WARN [karma]: No captured browser, open http://localhost:9876/
26 06 2018 11:00:51.095:INFO [karma]: Karma v2.0.0 server started at http://0.0.0.0:9876/
26 06 2018 11:00:51.095:INFO [launcher]: Launching browser Chrome with unlimited concurrency
26 06 2018 11:00:51.100:INFO [launcher]: Starting browser Chrome
26 06 2018 11:01:48.404:WARN [karma]: No captured browser, open http://localhost:9876/    
26 06 2018 11:01:48.665:INFO [Chrome 67.0.3396 (Mac OS X 10.11.6)]: Connected on socket UhrUQZiU8ZuG8qRwAAAA with id 31579746
Chrome 67.0.3396 (Mac OS X 10.11.6): Executed 1151 of 2149 (skipped 843) SUCCESS (0 secs / 0 secs)
26 06 2018 11:07:31.910:WARN [Chrome 67.0.3396 (Mac OS X 10.11.6)]: Disconnected (1 times), because no message in 10000 ms.
Chrome 67.0.3396 (Mac OS X 10.11.6) ERROR
Chrome 67.0.3396 (Mac OS X 10.11.6) ERROR
  Disconnected, because no message in 10000 ms.
Chrome 67.0.3396 (Mac OS X 10.11.6): Executed 1151 of 2149 (skipped 843) DISCONNECTED (5 mins 31.686 secs / 0 secs)
Chrome 67.0.3396 (Mac OS X 10.11.6) ERROR
Chrome 67.0.3396 (Mac OS X 10.11.6): Executed 1151 of 2149 (skipped 843) DISCONNECTED (5 mins 31.686 secs / 0 secs)

=============================== Coverage summary ===============================
Statements   : Unknown% ( 0/0 )
Branches     : Unknown% ( 0/0 )
Functions    : Unknown% ( 0/0 )
Lines        : Unknown% ( 0/0 )
Chrome 67.0.3396 (Mac OS X 10.11.6): Executed 1295 of 2149 (skipped 854) DISCONNECTED (6 mins 49.413 secs / 0 secs)

【问题讨论】:

转到项目根目录下的 ./coverage 文件夹。然后您可以打开 ./coverage/index.html 以查看覆盖率报告。 coverage/index.html 也将覆盖率显示为未知.. 我也面临同样的问题你找到解决办法了吗 【参考方案1】:

我遇到了同样的问题,并通过确保将angular.json 中的"sourceRoot" 属性设置为项目源文件的根文件夹来修复它。

ng cli uses the files in "sourceRoot" to compute coverage。

对于测试,sourceRoot 似乎没有做任何其他事情,所以测试运行并通过,但覆盖不起作用。

【讨论】:

以上是关于ng test --code-coverage 不打印覆盖率详细信息的主要内容,如果未能解决你的问题,请参考以下文章

“ng test”不能同时做覆盖率报告和TeamCity报告

markdown Angular CLI:ng lint,ng test,ng e2e

“ng e2e”可能因代理而失败,但“ng serve”和“ng test”正在运行

Angular 库二级入口点测试代码覆盖率问题

为 grails 运行 test-app -coverage 命令时出现错误,即使所有测试用例都通过了

运行“ng test”命令时找不到 JQuery