test(app): harden flaky e2e synchronization (#40556)

This commit is contained in:
Luke Parker
2026-08-05 12:31:45 +10:00
committed by GitHub
parent 9f38562237
commit 82a5796159
5 changed files with 116 additions and 42 deletions
+10 -5
View File
@@ -247,18 +247,23 @@ export async function installSseTransport<T>(
return {
server,
async waitForConnection(input = {}) {
await page.waitForFunction(
const connection = await page.waitForFunction(
(after) => {
const transport = (window as BrowserTransport).__testSseTransport
const connections = transport?.command({ type: "connections" }) as SseConnectionRecord[] | undefined
return connections?.some((connection) => connection.id > after)
return connections?.findLast((connection) => connection.id > after && connection.endedAt === undefined)
},
input.after ?? 0,
{ timeout: input.timeout },
)
return (await command<SseConnectionRecord[]>({ type: "connections" })).findLast(
(connection) => connection.id > (input.after ?? 0),
)!
let result: SseConnectionRecord | undefined
try {
result = await connection.jsonValue()
} finally {
await connection.dispose()
}
if (!result) throw new Error("SSE transport connection disappeared while waiting")
return result
},
send(payload, eventOptions) {
return command({ type: "send", deliveries: [{ payload, options: eventOptions }], burst: false })