当再添加一个测试文件时,纱线测试挂起 [英] Yarn test hangs when one more tests file is added

查看:16
本文介绍了当再添加一个测试文件时,纱线测试挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个包含多个测试套件 (Jest) 的项目,所有测试套件都在本地通过.我的 CircleCI 工作中有一个步骤,只需运行 yarn test.

I'm running a project that has several test suites (Jest), all passing locally. I have a step in my CircleCI job that simply runs yarn test.

问题是整个构建在 yarn test 步骤期间挂起.测试全部通过,但该步骤只是挂起,并在 10 分钟后超时.

The problem is that the entire build hangs during the yarn test step. The tests all pass, but the step just hangs, and times out after 10 min.

为了让事情更有趣,如果我从我的测试文件夹中删除一个测试套件文件,该步骤将通过.我可以删除任何测试文件,它仍然会通过.这让我相信我的测试没有任何问题.另外,如果我删除一个文件,然后添加一个只有一个虚拟测试的新文件,该步骤将再次挂起.

To make thing more interesting, if I remove one test suite file from my tests folder, the step will pass. I can remove any tests file, it will still pass. That leads me to believe there is nothing wrong with my tests. Also, if I remove one file, and add a new file with just one dummy test, the step will hang again.

我忽略了什么?

谢谢!

推荐答案

问题

我无法找到正确的解决方案,而且似乎没有人找到过.当测试按顺序运行(或单独运行)并且测试失败时,Jest 可以显示可读的错误消息.

Problem

I was not able the find the RIGHT solution and looks like no one has been. When the tests are run in sequence (or ran alone), and the tests fail, Jest can show a readable error message.

在并行模式(默认模式)下运行 Jest 时会出现问题.这就是为什么添加 -w=2 有帮助,因为它降低了并行性"到只有 2.

The problem happens when you run Jest in parallel mode (which is the default mode). That's why adding the -w=2 helped, it's because it decreased the "parallelity" to only 2.

可能 Jest 有一个错误,即当它们以并行模式运行时,它无法检测失败的测试.所以解决方案是始终使用强制顺序的配置.

Probably Jest has a bug that it can't detect failing tests when they're run in parallel mode. So the solution is to always use a config that forces sequence.

您基本上有以下选择:

npx jest --maxWorkers=1 # 连续运行测试

npx jest --runInBand # 相当于上面的

npx jest --detectOpenHandles # 等价于上面,加上一些额外的检查

它会稍微减慢测试速度,但在大多数情况下,差异不会很大.在我的情况下,差异以秒为单位,看:

It'll slow down the test speed a little bit, but in most cases, the difference won't be big. In my case, the difference was in the order of seconds, look:

使用 --detectOpenHandles 运行:

Test Suites: 26 passed, 26 total
Tests:       145 passed, 145 total
Snapshots:   0 total
Time:        24.093 s

在没有--detectOpenHandles的情况下运行:

Test Suites: 26 passed, 26 total
Tests:       145 passed, 145 total
Snapshots:   0 total
Time:        23.602 s

另外,我发现了这个文章,该人还表示,即使进行了 600 多次测试,他也没有注意到巨大的性能问题.

Also, I found this article in which the guy also states he hadn't noticed a huge performance issue, even with 600+ tests.

这篇关于当再添加一个测试文件时,纱线测试挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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