Jest watch mode mock restoration configuration to prevent memory leaks
0 reputation · 11 Sept 2023, 18:22 UTC
Goal: Keep Jest test suite memory consumption stable when running in watch mode while tests use mocked modules.
Constraint: Enabling restoreMocks guarantees each test starts with a clean module implementation but may add noticeable overhead because Jest deep‑clones modules; the current default keeps restoreMocksfalse to preserve speed.
Uncertainty: It is unclear whether the performance cost is acceptable in watch mode, where the Node process persists across test runs and leaks can accumulate, or whether an automatic opt‑in behavior should be introduced.
Should Jest automatically enable restoreMocks in watch mode to prevent memory leaks?
What level of performance impact would be considered acceptable for this safety guarantee?
Could a dedicated watch‑mode flag (e.g., watchRestoreMocks) provide a middle ground?