test(ui): проверить ожидание первого сообщения SSE
This commit is contained in:
1 parent
88a8b5f02f
commit
7a01e8d545
6 files changed
+55
-8
No files matched your search
@@ -1,9 +1,9 @@
|
||||
import type { Page } from '@playwright/test'
|
||||
|
||||
// Keep a response open; the browser test controls sample delivery independently of HTTP routes.
|
||||
export async function installOpenLiveStream(page: Page, path: string, sample: unknown) {
|
||||
export async function installOpenLiveStream(page: Page, path: string, sample: unknown, sendImmediately = true) {
|
||||
await page.clock.install()
|
||||
await page.addInitScript(({ path, sample }) => {
|
||||
await page.addInitScript(({ path, sample, sendImmediately }) => {
|
||||
const originalFetch = window.fetch.bind(window)
|
||||
window.fetch = async (input, init) => {
|
||||
const url = new URL(input instanceof Request ? input.url : String(input), location.href)
|
||||
@@ -18,12 +18,12 @@ export async function installOpenLiveStream(page: Page, path: string, sample: un
|
||||
}
|
||||
const heartbeat = () => controller.enqueue(encode(': heartbeat\r\n\r\n'))
|
||||
Object.assign(window, { sendLiveSample: send, sendLiveHeartbeat: heartbeat })
|
||||
send()
|
||||
if (sendImmediately) send()
|
||||
},
|
||||
})
|
||||
return new Response(stream, { headers: { 'Content-Type': 'text/event-stream' } })
|
||||
}
|
||||
}, { path, sample })
|
||||
}, { path, sample, sendImmediately })
|
||||
}
|
||||
|
||||
export async function resumeLiveStream(page: Page) {
|
||||
|
||||
Reference in new issue
Block a user