Mocha的代码覆盖率 [英] Code coverage with Mocha

查看:195
本文介绍了Mocha的代码覆盖率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Mocha来测试我的NodeJS应用程序.我无法弄清楚如何使用其代码覆盖功能.我尝试使用Google搜索,但没有找到任何合适的教程.请帮忙.

I am using Mocha for testing my NodeJS application. I am not able to figure out how to use its code coverage feature. I tried googling it but did not find any proper tutorial. Please help.

推荐答案

您需要一个额外的库来覆盖代码,而

You need an additional library for code coverage, and you are going to be blown away by how powerful and easy istanbul is. Try the following, after you get your mocha tests to pass:

npm install nyc

现在,只需将命令nyc放在现有测试命令的前面即可,例如:

Now, simply place the command nyc in front of your existing test command, for example:

{
  "scripts": {
    "test": "nyc mocha"
  }
}

这篇关于Mocha的代码覆盖率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆