test(app): stabilize reconnect offset timing

This commit is contained in:
Brendan Allan 2026-08-05 18:53:30 +08:00
parent 232ee3b10d
commit a81628ebfe
No known key found for this signature in database
GPG key ID: 41E835AEA046A32E

View file

@ -45,8 +45,7 @@ test("reports a divergent native offset once and ignores equal offsets and unrel
route.remove()
document.body.append(route)
await new Promise((resolve) => setTimeout(resolve, 0))
await frames(3)
await waitFor(() => calls.length === 1)
expect(calls).toEqual([[0, false]])
route.remove()
@ -197,3 +196,8 @@ async function frames(count: number) {
await new Promise<void>((resolve) => requestAnimationFrame(() => resolve()))
}
}
async function waitFor(condition: () => boolean) {
const deadline = performance.now() + 1_000
while (!condition() && performance.now() < deadline) await frames(1)
}