为什么我的 Jest 一跑就会挂掉,错误提示一会儿是 out of memory,一会儿是 EPIPE

2020-07-17 23:49:42 +08:00
 yazoox

windows 10 (1709)

node 10.19.0

Jest 26.0.1

机器有 32g 内存。编译和运行都没有问题,就是 jest 无法正常跑完。

这个是咋回事儿,没有头绪呢。

在 macos 下跑 jest 就没有问题

<--- Last few GCs --->

[39960:0000015619EDC4D0]   127030 ms: Scavenge 25.7 (30.5) -> 24.9 (30.5) MB, 0.8 / 0.0 ms  (average mu = 0.998, current mu = 0.999) allocation failure
[39960:0000015619EDC4D0]   129628 ms: Scavenge 25.8 (30.5) -> 24.9 (30.5) MB, 1.2 / 0.0 ms  (average mu = 0.998, current mu = 0.999) allocation failure
[39960:0000015619EDC4D0]   131365 ms: Scavenge 25.8 (30.5) -> 24.9 (30.5) MB, 0.8 / 0.0 ms  (average mu = 0.998, current mu = 0.999) allocation failure


<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 00000230F2BDC87C]
    1: StubFrame [pc: 00000230F2C0FAB5]
Security context: 0x00c35e29e6e9 <JSObject>
    2: initialize [0000011BDB729891] [C:\src\web-2nd\node_modules\jest-worker\build\workers\ChildProcessWorker.js:145] [bytecode=000001792A6C2509 offset=111](this=0x034bdb811831 <ChildProcessWorker map = 0000005E90AC1AD1>)
    3: _onExit [0000011BDB729901] [C:\src\web-2nd\node_modules\jest-worker\build\workers\ChildP...

FATAL ERROR: Committing semi space failed. Allocation failed - JavaScript heap out of memory
 1: 00007FF7C169832A v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+4506
 2: 00007FF7C1672DB6 node::MakeCallback+4534
 3: 00007FF7C1673730 node_module_register+2032
 4: 00007FF7C198C14E v8::internal::FatalProcessOutOfMemory+846
 5: 00007FF7C198C07F v8::internal::FatalProcessOutOfMemory+639
 6: 00007FF7C1B72874 v8::internal::Heap::MaxHeapGrowingFactor+9620
 7: 00007FF7C1B6986C v8::internal::ScavengeJob::operator=+24572
 8: 00007FF7C1B67EAC v8::internal::ScavengeJob::operator=+17980
 9: 00007FF7C1B70BF7 v8::internal::Heap::MaxHeapGrowingFactor+2327
10: 00007FF7C1B70C76 v8::internal::Heap::MaxHeapGrowingFactor+2454
11: 00007FF7C1C9AB9B v8::internal::Factory::AllocateRawWithImmortalMap+59
12: 00007FF7C1C9D50D v8::internal::Factory::NewRawOneByteString+77
13: 00007FF7C1C9CC5A v8::internal::Factory::NewStringFromTwoByte+154
14: 00007FF7C19A7ED1 v8::String::NewFromTwoByte+385
15: 00007FF7C15F3453 v8::internal::StackGuard::ArchiveSpacePerThread+24899
16: 00007FF7C1D7FF98 v8::internal::InterpreterDispatchDescriptor::InitializePlatformIndependent+584
17: 00007FF7C1D81953 v8::internal::InterpreterDispatchDescriptor::InitializePlatformIndependent+7171
18: 00007FF7C1D821DA v8::internal::InterpreterDispatchDescriptor::InitializePlatformIndependent+9354
19: 00007FF7C1D82471 v8::internal::InterpreterDispatchDescriptor::InitializePlatformIndependent+10017
20: 00007FF7C1D806B0 v8::internal::InterpreterDispatchDescriptor::InitializePlatformIndependent+2400
21: 00007FF7C1D81135 v8::internal::InterpreterDispatchDescriptor::InitializePlatformIndependent+5093
22: 00007FF7C19E74E3 v8::internal::Object::ToInt32+12803
23: 00007FF7C1C94CE3 v8::internal::wasm::WasmCodeManager::LookupCode+51395
24: 00000230F2BDC87C
error Command failed with exit code 134.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

或者

      throw er; // Unhandled 'error' event
      ^

Error: write EPIPE
    at ChildProcess.target._send (internal/child_process.js:762:20)
    at ChildProcess.target.send (internal/child_process.js:634:19)
    at ChildProcessWorker.send (C:\src\web-2nd\node_modules\jest-worker\build\workers\ChildProcessWorker.js:291:17)
    at WorkerPool.send (C:\src\web-2nd\node_modules\jest-worker\build\WorkerPool.js:32:34)
    at Farm._process (C:\src\web-2nd\node_modules\jest-worker\build\Farm.js:129:10)
    at Farm._enqueue (C:\src\web-2nd\node_modules\jest-worker\build\Farm.js:152:10)
    at Farm._push (C:\src\web-2nd\node_modules\jest-worker\build\Farm.js:159:12)
    at Promise (C:\src\web-2nd\node_modules\jest-worker\build\Farm.js:90:14)
    at new Promise (<anonymous>)
    at Farm.doWork (C:\src\web-2nd\node_modules\jest-worker\build\Farm.js:56:12)
Emitted 'error' event at:
    at process.nextTick (internal/child_process.js:766:39)
    at process._tickCallback (internal/process/next_tick.js:61:11)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
2918 次点击
所在节点    JavaScript
7 条回复
WittBulter
2020-07-18 02:38:20 +08:00
试一下 jest -w 1
msg7086
2020-07-18 03:19:35 +08:00
Let me Google that for you?

https://stackoverflow.com/q/38558989/2221631 看看能不能解决。
seki
2020-07-18 04:54:08 +08:00
换个 node 大版本
看看 Jest 周边的一些库是不是没有升到新版本
改变一下测试的数量,从 1 个开始
改变一下并行 worker 的数量
在 wsl 底下跑

都试试看
jiangzhuo
2020-07-18 09:39:22 +08:00
都 32G 了就给进程多分点内存呗。
yazoox
2020-07-18 11:52:20 +08:00
@jiangzhuo #4 这个…… 怎么指定 /分配?
yazoox
2020-07-18 11:54:19 +08:00
@seki #3 只跑一个 test,或者一个 suite 都没问题。
知道统一跑,就不行了。

另,怎么设定 worker 等参数?
jiangzhuo
2020-07-18 12:17:52 +08:00
@yazoox #5 node --v8-options 里有写

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/691025

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX