将--max-old-space-size值传递给生成的子进程

时间:2018-07-31 11:52:27

标签: node.js jestjs

我们正在使用jest作为我们的nodejs应用程序的测试框架。在运行测试时,我们遇到了内存问题。

*<--- Last few GCs --->
[31315:0x3aac760]   329728 ms: Mark-sweep 1322.4 (1460.2) -> 1322.4 (1461.2) MB, 2209.0 / 0.1 ms  allocation failure GC in old space requested
[31315:0x3aac760]   331935 ms: Mark-sweep 1322.4 (1461.2) -> 1322.3 (1428.7) MB, 2207.7 / 0.1 ms  last resort GC in old space requested
[31315:0x3aac760]   333970 ms: Mark-sweep 1322.3 (1428.7) -> 1322.3 (1428.7) MB, 2034.3 / 0.1 ms  last resort GC in old space requested
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x8d41da5879 <JSObject>
    1: set [native weak-collection.js:~27] [pc=0x3fe505d868c9](this=0x1677d030beb1 <JSWeakMap>,key=0xe7ed3f02f31 <Object map = 0x222ebd8ee4c9>,value=0x1223ab041861 <Object map = 0xf253f0023b9>)
    2: /* anonymous */(aka /* anonymous */) [--/api/node_modules/jest-util/build/deep_cyclic_copy.js:~64] [pc=0x3fe506627c4c](this=0xf1a02a822d1 <undefined>,key=0x8d41daf...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory*

根据建议,我尝试将--max-old-space-size设置为节点进程。但这不起作用,因为我们产生了一个子进程来执行测试,并且此参数没有传递给子进程。

spawn('yarn', ['test:specs'], { env: process.env });

我尝试将其作为jest配置的一部分,如下所示:

  testEnvironment: 'node',
  testEnvironmentOptions: { max_old_space_size: '4096' },

但是它不起作用。请建议是否有任何解决方法。

0 个答案:

没有答案