ng test --code-coverage not printing coverage details

ⅰ亾dé卋堺 提交于 2020-12-13 04:09:23

问题


When I run the tests using ng test --code-coverage I get the code coverage as unknown, not sure what might be going wrong. Any help here is appreciated.

> 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)

回答1:


I ran into the same problem and fixed it by making sure the "sourceRoot" property in the angular.json is set to the root folder for the project's source files.

The ng cli uses the files in "sourceRoot" to compute coverage.

It doesn't seem to do anything else with sourceRoot for tests, so the tests run and pass, but coverage doesn't work.



来源:https://stackoverflow.com/questions/51049229/ng-test-code-coverage-not-printing-coverage-details

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!