简体   繁体   English

如何执行 node js 应用程序的代码覆盖?

[英]How to perform code coverage of node js application?

Do we have a code coverage tool that detects how much code is covered.我们是否有一个代码覆盖工具来检测有多少代码被覆盖。 I don't want to have any testing framework here.我不想在这里有任何测试框架。 Just the way users use it, it should be able to give real time code coverage details.就像用户使用它的方式一样,它应该能够提供实时的代码覆盖率细节。 Is it possible?可能吗?

Well, yes – just run your application under a suitable coverage runner such as nyc :嗯,是的 - 只需在合适的覆盖运行程序下运行您的应用程序,例如nyc

Eg if you'd start your app with npm start , have nyc installed and run with例如,如果您使用npm start启动您的应用程序,请安装并运行nyc

nyc --reporter=lcov npm start

Of course you'll need to run for a while (so your users get to cover your app), and then capture the LCOV/HTML report generated.当然,您需要运行一段时间(这样您的用户才能覆盖您的应用程序),然后捕获生成的 LCOV/HTML 报告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM