Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

leader-close-probe.ts

39 lines1.2 KB

1import type { Page } from '@playwright/test'
2​
3// The browser probe that the leader-close checkpoints and their scenario tests share.
4// It stages tabs, reads each tab's observation, and reports when a tab is ready.
5export type ProbeObservation = {
6 phase: `starting` | `ready` | `failed`
7 failure?: string
8 isLeader: boolean
9 collectionStatus: string
10 publicIds: Array<string>
11 liveIds: Array<string>
12 liveStatus: string
13 publicEventKeys: Array<string>
14 liveEventKeys: Array<string>
15 authoredTxIds: Record<string, string>
16 syncRuns: number
17 heldAtCommitBoundary: boolean
18 reconciliationRequested: boolean
19 firstOutcome?: {
20 status: `fulfilled` | `rejected`
21 errorName?: string
22 message?: string
23 }
25​
26export async function observe(page: Page): Promise<ProbeObservation> {
27 return page.evaluate(() => window.__leaderCloseProbe!.observe())
29​
30export async function openProbe(page: Page, url: string): Promise<void> {
31 await page.goto(url)
32 await page.waitForFunction(
33 () =>
34 window.__leaderCloseProbe !== undefined &&
35 window.__leaderCloseProbe.observe().phase !== `starting`,
36 )
37 const state = await observe(page)
38 if (state.phase === `failed`) throw new Error(state.failure)