GitHub - A-kirami/vitest-browser-manual-mock (original) (raw)

vitest-browser-manual-mock-leak-repro

This repo exists to reproduce a Vitest Browser Mode bug with the smallest setup we could keep stable.

The repro is pure TypeScript. Vue components are not required.

Suggested GitHub repository name:

vitest-browser-manual-mock-leak-repro

Quick start

bun install bun run test:probe bun run test:target bun run repro

Expected:

Expected failure:

[vitest] There was an error when mocking a module
[birpc] rpc is closed, cannot call "resolveManualMock"

Summary

This repro demonstrates a Browser Mode failure where:

Minimal trigger

src/probe.spec.ts registers two manual mocks for the same module with two different raw ids:

src/target.spec.ts does not mock anything. It only imports another module that touches ~/modal again.

The failure appears when probe.spec.ts runs before target.spec.ts.

Files

Commands

Install dependencies:

Run each spec alone:

bun run test:probe bun run test:target

Run both specs together:

Why --no-cache is included

Vitest's default sequencer uses cached file stats and durations to decide file order. Without --no-cache, cached ordering can cause target.spec.ts to run first, which hides the leak.

Using --no-cache makes the repro behave like a fresh run and keeps the failing order stable.

Expected

Both specs should pass when run in the same Browser Mode process.

Actual

The combined run fails after src/probe.spec.ts passes.

Extra observation

This also affects vitest list on a fresh run:

It fails with:

Mock /src/modal.ts wasn't registered. This is probably a Vitest error. Please, open a new issue with reproduction.