events.js:288错误:使用Jest执行测试时写EPIPE

时间:2020-05-27 17:12:26

标签: reactjs jestjs react-testing-library

在将React Testing Library设置到一个新项目时,我遇到一个问题,该项目为多个项目生成通用的UI组件。在其中一个项目中,它是正确设置的,但是当我在该项目中添加React Testing Library和更新依赖项时,我可以运行测试,但不能运行所有测试。

如果我这样做yarn test,结果是:

Test Suites: 8 passed, 8 of 33 total
Tests:       84 passed, 84 total
Snapshots:   0 total
Time:        28 sevents.js:288
      throw er; // Unhandled 'error' event
      ^

Error: write EPIPE
    at ChildProcess.target._send (internal/child_process.js:806:20)
    at ChildProcess.target.send (internal/child_process.js:677:19)
    at ChildProcessWorker.send (C:\Users\user\workspace\project\node_modules\jest-worker\build\workers\ChildProcessWorker.js:291:17)
    at WorkerPool.send (C:\Users\user\workspace\project\node_modules\jest-worker\build\WorkerPool.js:32:34)
    at Farm._process (C:\Users\user\workspace\project\node_modules\jest-worker\build\Farm.js:129:10)
    at Farm._enqueue (C:\Users\user\workspace\project\node_modules\jest-worker\build\Farm.js:152:10)
    at Farm._push (C:\Users\user\workspace\project\node_modules\jest-worker\build\Farm.js:159:12)
    at C:\Users\user\workspace\project\node_modules\jest-worker\build\Farm.js:90:14
    at new Promise (<anonymous>)
    at Farm.doWork (C:\Users\user\workspace\project\node_modules\jest-worker\build\Farm.js:56:12)
Emitted 'error' event on ChildProcess instance at:
    at internal/child_process.js:810:39
    at processTicksAndRejections (internal/process/task_queues.js:79:11) {
  errno: 'EPIPE',
  code: 'EPIPE',
  syscall: 'write'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

我尝试做rm -rf node_modules,然后清理缓存,但没有用。

有帮助吗?

3 个答案:

答案 0 :(得分:0)

事实证明,通过更改package.json中的某些库,该错误消失了:

在(KO)之前:

"babel-jest": "^24.9.0",
"jest": "^26.0.1",

(确定)之后:

"babel-jest": "^26.0.1",
"jest": "^25.5.4",

答案 1 :(得分:0)

通过执行 yarn cache clean 解决了我的问题。如果您遇到类似于下图的管道错误。我认为这与内存泄漏有关。

enter image description here

答案 2 :(得分:0)

在我的情况下是节点的版本。我有版本 15(来自 Latest Features)并将其更改为稳定版本 14.17.3(来自 LTS)。

要知道您使用的是哪个版本,请在终端中使用 node -v。