From snapshotting the heap and reading the logs, it looks like initializeLanguageServiceInstance (see language-service.ts) gets called for each jest project, which keeps a cache of transpiled and instrumented code in memory (memoryCache) which never gets cleared
Workaround
If you encounter this issue, using ts-jest's isolatedModules might help.
In the example repo, run yarn test:isolated-modules as an example
š Bug Report
Memory usage is high when running ts-jest with jest projects.
To Reproduce
Steps to reproduce the behavior:
You will see tests running with a high heap size.
Expected behavior
Much lower memory usage.
Link to repo (highly encouraged)
https://github.com/richardcornelissen/ts-jest-projects-oom
Debug log:
Too large to inline, available at https://raw.githubusercontent.com/richardcornelissen/ts-jest-projects-oom/main/ts-jest.log
envinfo
Potential cause
From snapshotting the heap and reading the logs, it looks like
initializeLanguageServiceInstance
(see language-service.ts) gets called for each jest project, which keeps a cache of transpiled and instrumented code in memory (memoryCache
) which never gets clearedWorkaround
If you encounter this issue, using
ts-jest
'sisolatedModules
might help. In the example repo, runyarn test:isolated-modules
as an example