diff --git a/tests/browser-capabilities/indexeddb-runtime.spec.ts b/tests/browser-capabilities/indexeddb-runtime.spec.ts index e3fa690..84812c0 100644 --- a/tests/browser-capabilities/indexeddb-runtime.spec.ts +++ b/tests/browser-capabilities/indexeddb-runtime.spec.ts @@ -182,6 +182,15 @@ async function startLifecycleRuntime( __indexedDbLifecycleRuntime?: unknown; } ).__indexedDbLifecycleRuntime = runtime; + // Every status the runtime passes through, so a short-lived one (BLOCKED + // lasts blockedTimeoutMs) is seen however late the test looks. + const statuses: unknown[] = []; + runtime.subscribeStatus((status) => statuses.push(status)); + ( + globalThis as unknown as { + __indexedDbLifecycleStatuses?: unknown[]; + } + ).__indexedDbLifecycleStatuses = statuses; const opening = runtime.open(); ( globalThis as unknown as { @@ -240,6 +249,17 @@ async function lifecycleStatus(page: Page): Promise { }); } +async function lifecycleStatuses(page: Page): Promise { + return await page.evaluate( + () => + ( + globalThis as unknown as { + __indexedDbLifecycleStatuses?: unknown[]; + } + ).__indexedDbLifecycleStatuses ?? [], + ); +} + async function closeLifecycleRuntime(page: Page): Promise { await page.evaluate(() => { const runtime = ( @@ -1021,9 +1041,12 @@ test("fails a blocked v2 upgrade closed, then closes its late connection after t expect(blocker).toBe("OPEN"); await startLifecycleRuntime(page, name, 2, 500); + // BLOCKED lasts 500 ms. Polling getStatus() from the test (100, 250, 500, + // 1000 ms apart) missed it whenever the blocked event came late, as it + // sometimes does in WebKit, and then saw only the CLOSED that follows. await expect - .poll(async () => await lifecycleStatus(page)) - .toEqual({ + .poll(async () => await lifecycleStatuses(page)) + .toContainEqual({ kind: "BLOCKED", currentVersion: 1, targetVersion: 2,