Note: for Jest to detect a memory leak and throw an error both arguments are required i.e. detectLeaks
and logHeapUsage
.
10:45 nestjs-cats (master) ✗ yarn test --detectLeaks --logHeapUsage
yarn run v1.17.3
$ jest --detectLeaks --logHeapUsage
PASS src/auth/auth.controller.spec.ts (61 MB heap size)
PASS src/cats/cats.service.spec.ts (61 MB heap size)
PASS src/app.controller.spec.ts (61 MB heap size)
FAIL src/cats/cats.controller.spec.ts
● Test suite failed to run
EXPERIMENTAL FEATURE!
Your test suite is leaking memory. Please ensure all references are cleaned.
There is a number of things that can leak memory:
- Async operations that have not finished (e.g. fs.readFile).
- Timers not properly mocked (e.g. setInterval, setTimeout).
- Keeping references to the global scope.
at ../node_modules/@jest/core/build/TestScheduler.js:257:24
at asyncGeneratorStep (../node_modules/@jest/core/build/TestScheduler.js:131:24)
at _next (../node_modules/@jest/core/build/TestScheduler.js:151:9)
at ../node_modules/@jest/core/build/TestScheduler.js:156:7
at ../node_modules/@jest/core/build/TestScheduler.js:148:12
at onResult (../node_modules/@jest/core/build/TestScheduler.js:271:25)
PASS src/cats/cats.controller.e2e-spec.ts (72 MB heap size)
PASS src/auth/auth.service.spec.ts (77 MB heap size)
Test Suites: 1 failed, 5 passed, 6 total
Tests: 5 passed, 5 total
Snapshots: 0 total
Time: 2.338s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.