Comfy-Org / Comfy-Org/ComfyUI_frontend
test: Worker fake in vitest.setup.ts is not constructible
- Dominant language
- TypeScript
- Stars
- 2k
- Forks
- 704
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 512
Description
## Problem
`vitest.setup.ts` fakes `Worker` for `extendable-media-recorder`:
```ts
globalThis.Worker = vi.fn(() => ({
postMessage: vi.fn(),
terminate: vi.fn(),
...
}))
```
The implementation is an arrow function, and arrows are not constructors, so `new Worker()` throws rather than returning the fake. Checked directly against `@vitest/spy@4.1.10`:
```
vi.fn(arrow) -> THROWS: () => ({ postMessage: 1 }) is not a constructor
vi.fn(function) -> new() ok, keys: ["postMessage"]
```
vitest emits its own warning for this: `the vi.fn() mock did not use 'function' or 'class' in its implementation`.
## Impact
Latent today. Every `extendable-media-recorder` importer mocks the module, so nothing reaches `new Worker()`. The first test that constructs a Worker for real will hit a confusing constructor error rather than the fake.
Note this was already broken before #14836. That PR changed the line from `vi.fn().mockImplementation(impl)` to `vi.fn(impl)`, which fixes a separate problem (the implementation surviving `mockReset`) but leaves the constructor problem in place.
## Fix
```ts
globalThis.Worker = vi.fn(function () {
return { postMessage: vi.fn(), terminate: vi.fn(), ... }
})
```
Or drop the fake if nothing needs it, since the module is mocked at every call site anyway.
## Context
Found while reviewing #14836.
Contributor guide
Research direction
Start in vitest.setup.ts and inspect the Worker fake used for extendable-media-recorder. Change the implementation so new Worker() can construct the fake, or confirm the fake can be removed because the module is mocked at every call site. Verify that construction no longer throws or emits the vi.fn() warning and that existing tests still pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100