reactjs - 升级到最新版本时的开玩笑错误 - 工作进程未能正常退出
问题描述
我最近将我的 jest 包更新到 v24 的最新版本,并且在运行我的单元测试时,我在测试套件运行结束时得到了这个:
A worker process has failed to exit gracefully and has been force exited.
This is likely caused by tests leaking due to improper teardown.
Try running with --runInBand --detectOpenHandles to find leaks.
我添加--detectOpenHandles
了我的测试命令,消息在下一次运行中发送。我不知道如何看待它,因为 detectOpenHandles 旨在查找打开的句柄而不是修复它,所以消息如何不会在下一次运行中出现,并且没有其他消息可以指导我解决可能的问题。
有没有人遇到过类似的行为?补充一下,我现在使用的是最新版本的 jest,即 27.2.0。
解决方案
根据我的研究,错误发生在以下情况:
- 异步函数未完成
- 承诺功能未完成
- Websocket、数据库或任何其他具有连接/断开方法的东西在测试结束前没有断开连接
该错误没有提到即使使用 --detectOpenHandles 标志,测试也会在大多数情况下挂起,这可能是您没有看到任何有用的调试消息的原因。
从文档中:
Attempt to collect and print open handles preventing Jest from exiting cleanly. Use this in cases where you need to use --forceExit in order for Jest to exit to potentially track down the reason. This implies --runInBand, making tests run serially. Implemented using async_hooks, so it only works in Node 8 and newer. This option has a significant performance penalty and should only be used for debugging.
正如文档中所说,您可以尝试使用 --detectOpenHandles 和 --forceExit 标志运行测试。这意味着测试将连续运行,并且当测试由于不正确的拆卸而无法完成时,每个测试都会强制退出。让我知道这个是否奏效。
推荐阅读
- python - 需要给列中的每个值加上值
- python - 通过 Python 从结果 ElasticSearch 中删除重复项
- python - Django:ValidationError ['ManagementForm 数据丢失或已被篡改']
- macos - 如何像 Python3 一样在 MacOS X 终端中运行 Lua?
- lua - 如何在LUA中重新启动游戏时停止声音
- excel - 如何在网页提取期间按钮自动点击网页后提取数据
- c - 为什么我的自动变量总是给出 0 而不是垃圾值?
- python - 如何使用 python 查找 tiff 文件中存在的图像(页面)的原始格式?
- javascript - 为什么单击单个删除按钮时除了一个图像之外的所有图像都被删除?
- python - 调试我的二叉树搜索和算法