Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest appears unaffected by node --max-old-space-size option

I have been working to overcome apparent memory leaks when running jest that are described here: https://github.com/facebook/jest/issues/7874

I would like to just give jest a whole bunch of heap space so that my tests will complete in spite of the leaks. However, using this command line:

node --max-old-space-size=8192 --expose-gc ./node_modules/.bin/jest --no-cache --runInBand --logHeapUsage

I still get "Javascript heap out of memory" at around 1500MB of heap usage. If I run:

node --max-old-space-size=8192

and then do:

> v8.getHeapStatistics()
{
   ...
   heap_size_limit: 8640266240
   ...
}

so clearly I can affect node's heap size. But it somehow is not affecting jest.

Node: 16.13.0 Jest: 27.4.4 Any thoughts?

like image 919
Eric Hill Avatar asked Dec 01 '25 01:12

Eric Hill


1 Answers

Perhaps one of these settings in your jest.config.js can fix it for you:

{
    maxWorkers: 1,
    globals: {
        'ts-jest': {
            isolatedModules: true
        }
    }
}

I think I remember having the same issue as you, and I solved it with all this configuration. Not sure which part was the difference-maker, but just give it a try, I would say.

like image 121
Milo Avatar answered Dec 03 '25 14:12

Milo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!