cloudflare / cloudflare/workers-sdk
🐛 BUG: Vitest `__mocks__` not working when using `@cloudflare/vitest-pool-workers`
- Dominant language
- TypeScript
- Stars
- 4.5k
- Forks
- 1.5k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 183
Description
### Which Cloudflare product(s) does this pertain to?
Workers Vitest Integration
### What versions are you using?
2.1.8 [vitest], 0.5.40 [@cloudflare/vitest-pool-workers]
### What operating system and version are you using?
macIS Sequoia 15.1.1
### Please provide a link to a minimal reproduction
https://github.com/saitolume/workers-sdk-bug-report
### Describe the Bug
When using `@cloudflare/vitest-pool-workers`, the mocks defined in Vitest's `__mocks__` directory do not work as expected.
- Expected behavior:
Modules defined in the `__mocks__` directory should automatically be used as mocks.
- Actual behavior:
When using `@cloudflare/vitest-pool-workers`, the modules in `__mocks__` are not applied. Instead, Vitest's default mocking behavior is used.
### Please provide any relevant error logs
```
pnpm run test:fail
> @ test:fail /workers-sdk-bug-report
> vitest run --config vitest.fail.config.ts
RUN v2.1.8 /workers-sdk-bug-report
[vpw:inf] Starting isolated runtimes for vitest.fail.config.ts...
❯ index.test.ts (1)
× uuid
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL index.test.ts > uuid
AssertionError: expected undefined to be 'expected' // Object.is equality
- Expected:
"expected"
+ Received:
undefined
❯ index.test.ts:7:16
5|
6| test('uuid', () => {
7| expect(v4()).toBe('expected')
| ^
8| })
9|
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ [1/1]⎯
Test Files 1 failed (1)
Tests 1 failed (1)
Start at 00:51:16
Duration 1.04s (transform 10ms, setup 0ms, collect 25ms, tests 6ms, environment 1ms, prepare 107ms)
[vpw:dbg] Shutting down runtimes...
ELIFECYCLE Command failed with exit code 1.
```
Contributor guide
Assessment
This issue has not been assessed yet.