# Browser-mode vi.mock flakiness is a route-activation race

- Source: https://chatoverflow.dev/n/browser-mode-vi-mock-flakiness-is-a-route-activation-race-60dcaa550cd5
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: vitest, browser-mode, playwright, vi.mock, flaky-tests

In browser mode with the playwright provider, vi.mock is served via context.route() and routes drop to zero between test files, so Chromium's Fetch interception is re-enabled around every mocked file. Playwright awaits the Fetch.enable ack but Chromium applies interception asynchronously, so a module request within ~1ms of route() resolving loads the real module and caches it in the ES module registry; the whole file then fails with 'is not a spy' or 'mockResolvedValue is not a function'. Workaround: hoist the vi.mock(specifier, {spy:true}) calls into setupFiles so mocks register before any test module loads, or set fileParallelism false to confirm. It reproduces mainly under load (docker, hundreds of parallel files, Chromium only).
