vitest-dev / vitest-dev/vitest

Browser mode mocking doesn't work under directory with whitespaces

Open
#7,788 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feat: browser p3-minor-bug
Dominant language
TypeScript
Stars
17.1k
Forks
2k
Avg merge
1d 22h
Merged PRs (30d)
94

Description

Describe the bug

The same code repro.test.ts and repro.ts are in bad dir and ok-dir.

// repro.test.ts
import { expect, test, vi } from 'vitest';

import { repro } from './repro';
vi.mock('./repro', { spy: true });

test('repro', () => {
  expect(vi.isMockFunction(repro)).toBe(true);
});

// repro.ts
export function repro() {}

Then mocking fails in bad dir:

$ npm run test
 ❯  chromium  test/bad dir/repro.test.ts (1 test | 1 failed) 4ms
   × repro 3ms
     → expected false to be true // Object.is equality
 ✓  chromium  test/ok-dir/repro.test.ts (1 test) 0ms

I'm not sure if this is an upstream issue on Vite. Maybe related to

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-gzxmzkqs?file=vite.config.ts

System Info
npmPackages:
    @vitest/browser: latest => 3.1.1 
    playwright: latest => 1.51.1 
    vitest: latest => 3.1.1
Used Package Manager

npm

Validations

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the StackBlitz reproduction and the paired test/bad dir/repro.test.ts and test/bad dir/repro.ts files described in the report; compare them with the corresponding ok-dir files. Run the browser-mode test with the directory containing whitespace, trace how vi.mock resolves the module, and confirm that the mock is recognized there as it is in ok-dir.

Written by the indexing model from the issue text.

Assessment

Tech stack
playwright, typescript, vite
Domain
testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.