#7679 Vitest __mocks__ not working when using @cloudflare/vitest-pool-workers
Feature parity issue: vitest __mocks__ directory convention not supported. Clear reproduction. 5 emoji reactions. May be inherent limitation of isolated workerd runtimes.
Keep open; document as limitation if intentional; suggest vi.mock() workaround
Analysis Report
Issue Review: cloudflare/workers-sdk#7679
Summary
Vitest's __mocks__ directory feature doesn't work when using @cloudflare/vitest-pool-workers.
Findings
- Created: 2025-01-06
- Updated: 2025-10-30
- Version: vitest 2.1.8, @cloudflare/vitest-pool-workers 0.5.40 -> latest 0.12.6
- Component: vitest-pool-workers
- Labels: bug, vitest
- Comments: 0
Key Evidence
- Reproduction repo provided: https://github.com/saitolume/workers-sdk-bug-report
- Issue:
__mocks__directory modules not automatically applied as mocks - Expected: Standard vitest behavior where
__mocks__/uuid.tswould mock the uuid module - Actual: Mock not applied, test fails because
v4()returns actual UUID instead of mock value - No comments or maintainer response in over a year
- 5 emoji reactions indicating user interest
- This is a feature parity issue - vitest-pool-workers doesn't support
__mocks__directory convention - No PRs found addressing this
Recommendation
Status: KEEP OPEN
Reasoning: This is a valid bug affecting vitest feature parity. The __mocks__ directory convention is a standard vitest/jest feature that users expect to work. The issue has a clear reproduction and 5 emoji reactions showing user demand. However, this may be an inherent limitation of how vitest-pool-workers runs tests in isolated workerd runtimes.
Action: Keep open. May require documentation if this is an intentional limitation. Users should use explicit vi.mock() calls as a workaround.
Suggested Comment
Thanks for the detailed reproduction. This appears to be a limitation of how vitest-pool-workers runs tests in isolated workerd runtimes - the
__mocks__directory convention may not be supported due to the module resolution differences.Workaround: Use explicit
vi.mock()calls instead:import { vi } from 'vitest'; vi.mock('uuid', () => ({ v4: () => 'expected' }));Could you confirm if explicit
vi.mock()works in your case? If so, we should document this as a known limitation of vitest-pool-workers.Are you still experiencing this with the latest @cloudflare/vitest-pool-workers version (0.12.6)?
Notes & Feedback (0)
No notes yet.