Jest的代码覆盖率 [英] Code coverage for Jest

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

问题描述

有没有办法在Javascript Jest测试框架中建立基于Jasmine的代码覆盖?

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

内部框架不要打印出它获得的代码覆盖率。我也尝试过使用伊斯坦布尔毯子 JSCover ,但它们都不起作用。

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 时,我可以在命令行看到代码覆盖率,并通过传递 - 覆盖率创建一个覆盖目录到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天全站免登陆