玩笑+木偶戏无法获得测试报道 [英] Can't get test coverage with jest + puppeteer

查看:65
本文介绍了玩笑+木偶戏无法获得测试报道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有项目 Excellent.js 设置用于使用 puppeteer ,它可以成功运行所有测试,可以在Travis CI上看到 a>.

I have project Excellent.js setup for automatic testing with jest and puppeteer, which successfully runs all the tests, which can be seen on Travis CI.

但是在进行大量配置调整后,我无法使它报告正确的覆盖范围.不管执行什么测试,覆盖范围都不会完全反映出来.

But after a lot of configuration tweaks I have been unable to make it report correct coverage. No matter what tests are executed, the coverage does not reflect it at all.

该库仅包含一个JavaScript文件excellent.js,而我的

The library contains only a single JavaScript file excellent.js, and my jest.config.js was set up as instructed for coverage:

module.exports = {
    collectCoverage: true,
    collectCoverageFrom: [
        'src/excellent.js'
    ],
    testURL: 'http://localhost/',
    setupFiles: [
        './src/excellent.js'
    ]
};

这里是所有测试,如果通过您先进行npm install,然后进行npm test.

Here're all the tests, which all pass if you do first npm install, and then npm test.

那我想念什么?为什么我无法正确报告承保范围?

So what am I missing? Why can't I get the coverage reported correctly?

推荐答案

问题

大多数测试都使用Puppeteer,并且在Puppeteer提供的浏览器中执行代码时,Jest代码覆盖率报告中未反映该代码执行情况.

Most of the tests are using Puppeteer and when the code is executed in the browser provided by Puppeteer, that code execution is not reflected in the Jest code coverage reports.

解决方案

所有测试都不需要Puppeteer,因此我将它们重构为Jest测试.现在,代码覆盖范围是准确的,并且当前为:

None of the tests require Puppeteer so I refactored them as Jest tests. The code coverage is now accurate and is currently the following:

excellent.js | 63.47 | 48.7 | 57.78 | 62.96

我通过这些更改创建了拉动请求.

I created a pull request with these changes.

其他信息

现在可以生成以下代码的报告:木偶页面,并且有一个库可帮助在伊斯坦布尔查看,但那些代码覆盖率报告是独立于Jest生成的.

It is now possible to generate code coverage reports for Puppeteer pages and there is a library to help view them in Instanbul but those code coverage reports are generated independently from Jest.

要在Puppeteer页面中进行测试并使Jest生成的报告中反映出这些测试的覆盖范围,则需要将Puppeteer页面覆盖率报告与Jest覆盖率报告合并.

To do testing in Puppeteer pages and have the coverage from those tests reflected in the reports generated by Jest would require merging the Puppeteer page coverage reports with the Jest coverage report.

这篇关于玩笑+木偶戏无法获得测试报道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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