Description
🚨 As of Node 21.1.0, this has been fixed upstream. Hopefully the fixes will be backported to v18 and v20 as well (as of writing (Oct. 26 2023) they have not. Node 18.20.0 and Node 20.10.0 have the backports), but that is up to the Node.js project and nothing we control from here. Note that (native) ESM still has memory leaks - that can be tracked here: #14605. If you're unable to upgrade your version of Node, you can use --workerIdleMemoryLimit
in Jest 29 and later. See https://jestjs.io/docs/configuration/#workeridlememorylimit-numberstring 🚨
Version
27.0.6
Steps to reproduce
- Install the latest Node JS (16.11.0 or later) or use the appropriate Docker image
- Set up a project with a multiplicity Jest tests
- Run
node --expose-gc node_modules/.bin/jest --logHeapUsage
and see how the memory consumption starts increasing.
Expected behavior
Since Jest calls global.gc()
when Garbage Collector is exposed and --logHeapUsage
flag is present, the memory usage should be stable.
Actual behavior
The memory usage increases with every new test
Additional context
We had some issues with Jest workers consuming all available RAM both on CI machine and locally.
After doing some research, we found that if we run Jest like the following node --expose-gc node_modules/.bin/jest --logHeapUsage
, the heap size remains stable. After upgrading to Node JS v16.11.0, the issue was back. Node v16.10.0 works fine. I believe it was something accidentally introduced in the new Node, but it might be useful to take a look at this from Jest perspective in search of possible workarounds.
I'm also having the same behavior on my working machine, environment of which I'm pasting below 👇🏻
Environment
System:
OS: macOS 11.6
CPU: (8) x64 Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
Binaries:
Node: 16.11.0 - ~/.nvm/versions/node/v16.11.0/bin/node
Yarn: 1.22.0 - ~/SomeFancyDir/webapp/node_modules/.bin/yarn
npm: 8.0.0 - ~/.nvm/versions/node/v16.11.0/bin/npm
npmPackages:
jest: 27.0.6 => 27.0.6