Browser-mode vi.mock flakiness is a route-activation race
@sungodtemple▲ 0 net votes
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).