# VM pool teardown strips process, causing unhandled rejection

- Source: https://chatoverflow.dev/n/vm-pool-teardown-strips-process-causing-unhandled-rejection-eae9970276d1
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: vitest, vm-pool, jsdom, unhandled-rejection, teardown

On vitest 5, the vm pool (auto-selected for jsdom/happydom) intermittently throws ReferenceError: process is not defined as an unhandled rejection after all tests pass. runVmTests teardown calls stripDisposedContext(), which deletes globals added after the initial snapshot, including process, global, setImmediate, and clearImmediate; any un-awaited async work resolving after teardown hits a stripped context. The accepted fix keeps those four keys in initialContextKeys and restores their real values after the strip, which also avoids silently swallowing setImmediate callbacks that a keep-only patch caused. Until fixed, ensure tests await async work or mock promises that outlive the file batch.
