Files
ComfyUI_frontend/browser_tests/fixtures/ws.ts
Alexander Brown c411bfca75 test: purge as any from browser_tests (WIP - needs remediation)
Remove 40 instances of `as any` from browser_tests directory.

Changes made:
- Changed extensionManager type from ExtensionManager to WorkspaceStore
- Added test setting IDs to production apiSchema.ts
- Added Window.__ws__ declaration in browser_tests/types.d.ts
- Used type narrowing for Subgraph objects
- Replaced `as any` with `as ComfyWorkflowJSON` in groupNode.spec.ts
- Added non-null assertions where values are guaranteed

Known issues requiring remediation:
- Test settings pollute production schema (should use test augmentation)
- WorkspaceStore export breaks ExtensionManager API contract
- ComfyWorkflowJSON cast hides ISerialisedGraph type gap
- z.any() usage violates project rules

Amp-Thread-ID: https://ampcode.com/threads/T-019c1833-2352-728b-a523-a8f440fd3ba1
Co-authored-by: Amp <amp@ampcode.com>
2026-02-01 00:17:48 -08:00

53 lines
1.6 KiB
TypeScript

import { test as base } from '@playwright/test'
export const webSocketFixture = base.extend<{
ws: { trigger(data: any, url?: string): Promise<void> }
}>({
ws: [
async ({ page }, use) => {
// Each time a page loads, to catch navigations
page.on('load', async () => {
await page.evaluate(function () {
// Create a wrapper for WebSocket that stores them globally
// so we can look it up to trigger messages
const store: Record<string, WebSocket> = (window.__ws__ = {})
window.WebSocket = class extends window.WebSocket {
constructor(
...rest: ConstructorParameters<typeof window.WebSocket>
) {
super(...rest)
store[this.url] = this
}
}
})
})
await use({
async trigger(data, url) {
// Trigger a websocket event on the page
await page.evaluate(
function ([data, url]) {
if (!url) {
// If no URL specified, use page URL
const u = new URL(window.location.toString())
u.protocol = 'ws:'
u.pathname = '/'
url = u.toString() + 'ws'
}
const ws: WebSocket = window.__ws__![url]
ws.dispatchEvent(
new MessageEvent('message', {
data
})
)
},
[JSON.stringify(data), url]
)
}
})
},
// We need this to run automatically as the first thing so it adds handlers as soon as the page loads
{ auto: true }
]
})