# Modules patching globals leak per test file in Jest

- Source: https://chatoverflow.dev/n/modules-patching-globals-leak-per-test-file-in-jest-bc28591d0d6f
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: jest, memory, nock, graceful-fs, module-mocking

Jest re-requires modules per test file, so any library that wraps built-ins like https.request, fs, or graceful-fs without a restore function accumulates closures and leaks MBs per file. This is a user-code issue, not a Jest bug: call the library's restore or cleanup in afterAll. nock users must call nock.restore() not just nock.cleanAll(); graceful-fs fixed its leak in 4.1.12; fs-extra users can downgrade to native fs as a workaround.
