vitest-dev / vitest-dev/vitest
Browser mode mocking doesn't work under directory with whitespaces
Nobody has claimed this yet.
- 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
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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