如何使用 Jest 获取代码覆盖率报告? [英] How to get the code coverage report using Jest?

查看:37
本文介绍了如何使用 Jest 获取代码覆盖率报告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在基于 Jasmine 的 JavaScript Jest 测试框架中实现代码覆盖?

Is there a way to have code coverage in the JavaScript Jest testing framework, which is built on top of Jasmine?

内部框架打印出它得到的代码覆盖率.我也试过使用 IstanbulblanketJSCover,但都没有工作.

The internal framework does not print out the code coverage it gets. I've also tried using Istanbul, blanket, and JSCover, but none of them work.

推荐答案

使用Jest 21.2.1时,可以在命令行看到代码覆盖率,并通过传递创建覆盖率目录--coverage 到 Jest 脚本.以下是一些示例:

When using Jest 21.2.1, I can see code coverage at the command line and create a coverage directory by passing --coverage to the Jest script. Below are some examples:

我倾向于在本地安装 Jest,在这种情况下,命令可能如下所示:

I tend to install Jest locally, in which case the command might look like this:

npx jest --coverage

我假设(虽然尚未确认),如果我全局安装 Jest,这也可以工作:

I assume (though haven't confirmed), that this would also work if I installed Jest globally:

jest --coverage

非常稀疏的文档在这里

当我导航到 coverage/lcov-report 目录时,我发现了一个可以加载到浏览器中的 index.html 文件.它包括在命令行打印的信息,以及附加信息和一些图形输出.

When I navigated into the coverage/lcov-report directory I found an index.html file that could be loaded into a browser. It included the information printed at the command line, plus additional information and some graphical output.

这篇关于如何使用 Jest 获取代码覆盖率报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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