出现 TypeError:并行运行 Jest 测试时将循环结构转换为 JSON

问题描述 投票:0回答:1

并行运行 Jest 测试时出现以下错误。 当单独运行每个测试或使用 --RunInBand 时,它们都通过并且似乎工作正常。

Test suite failed to run

    Jest worker encountered 4 child process exceptions, exceeding retry limit

      at ChildProcessWorker.initialize (node_modules/jest-worker/build/workers/ChildProcessWorker.js:181:21)

node:internal/child_process/serialization:159
    const string = JSONStringify(message) + '\n';
                   ^

TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Socket'
    |     property '_httpMessage' -> object with constructor 'ClientRequest'
    --- property 'socket' closes the circle
    at stringify (<anonymous>)
    at writeChannelMessage (node:internal/child_process/serialization:159:20)
    at process.target._send (node:internal/child_process:845:17)
    at process.target.send (node:internal/child_process:745:19)
    at reportSuccess (C:\Users\User1\Documents\App1\App2\api-gateway\node_modules\jest-worker\build\workers\processChild.js:82:11)

我希望所有测试都能运行并成功。

node.js typescript testing jestjs backend
1个回答
0
投票

不确定为什么会发生这种情况,但 Jest Worker 在测试结果中有一个循环引用对象(例如 HTTP 连接)。

使用调试器并在第 82 行设置断点

node_modules/jest-worker/build/workers/processChild.js

function reportSuccess(result) {
  if (!process || !process.send) {
    throw new Error('Child can only be used on a forked process');
  }
  process.send([_types.PARENT_MESSAGE_OK, result]);  // set a breakpoint here
}

然后您可以在

testResults
result
属性下看到错误。

© www.soinside.com 2019 - 2024. All rights reserved.