Skip to content

Instantly share code, notes, and snippets.

@mmyoji
Last active June 7, 2023 12:29
Show Gist options
  • Save mmyoji/9ffaab4076e3ecd0cf6f80d98976e626 to your computer and use it in GitHub Desktop.
Save mmyoji/9ffaab4076e3ecd0cf6f80d98976e626 to your computer and use it in GitHub Desktop.
Detect memory leak w/ Jest

ref: https://stackoverflow.com/a/62885391

Run test with the following command:

node --expose-gc ./node_modules/.bin/jest --runInBand --logHeapUsage

workaround: https://jestjs.io/docs/configuration#workeridlememorylimit-numberstring

  • Bump jest to v29.5 or over
  • Set workerIdleMemoryLimit in jest.config.ts
import { type Config } from "jest";

const config: Config = {
  workerIdleMemoryLimit: "500MB",
};

export default config;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment