Vitest's isolate:false buys you 30% speed and a class of flake you cannot grep for
Blog post from Mergify
Disabling per-test module isolation in Vitest by setting `isolate: false` in `vitest.config.ts` can lead to a 30% increase in testing speed, but it also introduces a risk of subtle, hard-to-detect bugs due to cross-file state sharing, which appear similar to ordinary logic errors. These issues arise from module-level singletons that persist across test files, causing tests to fail intermittently if they depend on shared state. While reverting to `isolate: true` can temporarily resolve these failures, it doesn't address the underlying problem of state-sharing bugs. The recommended solution involves conducting an audit to identify and refactor module-level mutable states in production code, replacing them with class-based instances or ensuring resets before each test. This approach helps maintain the speed advantage without compromising test reliability. Tools like Mergify Test Insights can assist in identifying these cross-file dependencies by tagging related test files, providing a clearer picture of the source of the issue.