mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-27 10:14:06 +00:00
- Add typescript/no-explicit-any override for browser_tests/**/*.ts - Fix 9 violations with proper types instead of any - Add TestGraphAccess interface for typed node access - Add function overloads to getExportedWorkflow for proper return types - Fix floating promise in colorPalette.spec.ts Amp-Thread-ID: https://ampcode.com/threads/T-019c1854-3c3c-723d-8ce6-183ce06fcf1b Co-authored-by: Amp <amp@ampcode.com>
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import { test as base } from '@playwright/test'
|
|
|
|
export const webSocketFixture = base.extend<{
|
|
ws: { trigger(data: unknown, 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 }
|
|
]
|
|
})
|