gpt4 book ai didi

reactjs - 升级到最新版本时出现的 Jest 错误 - 工作进程未能正常退出

转载 作者:行者123 更新时间:2023-12-04 11:43:24 25 4
gpt4 key购买 nike

我最近将我的 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。

最佳答案

根据我的研究,错误发生在:

  • 异步函数未完成
  • 一个promise函数没有完成
  • 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 标志运行测试。这意味着测试将连续运行,并且每个测试都将在由于拆卸不当导致测试未完成时强制退出。让我知道这个是否奏效。

    关于reactjs - 升级到最新版本时出现的 Jest 错误 - 工作进程未能正常退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69244089/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com