Comfy-Org / Comfy-Org/ComfyUI_frontend
test: synchronize ComfyApi WebSocket handler setup
- Dominant language
- TypeScript
- Stars
- 2k
- Forks
- 699
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 490
Description
## Summary
`src/scripts/api.featureFlags.test.ts` contains several tests that use this pattern:
```ts
const initPromise = api.init()
// Invoke mocked WebSocket handlers
await initPromise
```
`ComfyApi.init()` returns `void`, so awaiting its return value does not synchronize socket initialization. The tests currently pass because the Vitest distribution is `localhost` and WebSocket handlers are registered synchronously, but the pattern is fragile if socket creation needs to await authentication or other asynchronous setup.
## Scope
- Introduce a small test helper that calls `ComfyApi.init()` and waits until the fresh WebSocket mock has registered both the `open` and `message` handlers.
- Migrate all identical initialization patterns in `api.featureFlags.test.ts` together.
- Keep the public production `ComfyApi.init()` signature unchanged unless there is a separate production requirement to make initialization awaitable.
## Acceptance criteria
- No test treats the return value of `ComfyApi.init()` as a promise.
- Tests dispatch mocked WebSocket events only after the current mock has registered the required handlers.
- Feature flag and server-message tests continue to pass.
- Coverage includes an asynchronously delayed socket-handler registration path.
## Context
Raised during review of #14041: https://github.com/Comfy-Org/ComfyUI_frontend/pull/14041#discussion_r3681871605
Contributor guide
Assessment
This issue has not been assessed yet.