mirror of
https://github.com/hanzoai/insights-js.git
synced 2026-10-30 18:34:19 +00:00
Bulk rename across 989 files: - Package names: posthog-js → @hanzo/insights, posthog-node → @hanzo/insights-node, etc. - Repository URLs: posthog/posthog-js → hanzoai/insights-js - Brand names: PostHog → Insights - File renames: 259 reference JSON files, source files, workflow files - Directory rename: eslint-plugin-posthog-js → eslint-plugin-insights Remaining: 8 refs to @posthog/rrweb-* (real npm deps, need fork+publish)
55 lines
1.7 KiB
TypeScript
55 lines
1.7 KiB
TypeScript
import { Page } from '@playwright/test'
|
|
import { EventName } from '@/types'
|
|
import { expect } from './insights-playwright-test-base'
|
|
|
|
export async function pollUntilEventCaptured(
|
|
page: Page,
|
|
event: EventName,
|
|
wait = 200,
|
|
attempts = 0,
|
|
maxAttempts = 50
|
|
): Promise<void> {
|
|
const captures = await page.capturedEvents()
|
|
if (captures.some((capture) => capture.event === event)) {
|
|
return
|
|
} else if (attempts < maxAttempts) {
|
|
await page.waitForTimeout(wait)
|
|
return pollUntilEventCaptured(page, event, wait, attempts + 1, maxAttempts)
|
|
} else {
|
|
throw new Error('Max attempts reached without finding the expected event')
|
|
}
|
|
}
|
|
|
|
export async function assertThatRecordingStarted(page: Page) {
|
|
const captures = await page.capturedEvents()
|
|
|
|
expect(captures.map((c) => c.event)).toEqual(['$snapshot'])
|
|
const capturedSnapshot = captures[0]
|
|
|
|
expect(capturedSnapshot).toBeDefined()
|
|
|
|
expect(capturedSnapshot!['properties']['$snapshot_data'].length).toBeGreaterThan(2)
|
|
|
|
// a meta and then a full snapshot
|
|
expect(capturedSnapshot!['properties']['$snapshot_data'][0].type).toEqual(4) // meta
|
|
expect(capturedSnapshot!['properties']['$snapshot_data'][1].type).toEqual(2) // full_snapshot
|
|
}
|
|
|
|
export async function pollUntilCondition(
|
|
page: Page,
|
|
fn: () => boolean | Promise<boolean>,
|
|
wait = 200,
|
|
attempts = 0,
|
|
maxAttempts = 50
|
|
): Promise<void> {
|
|
const condition = await fn()
|
|
if (condition) {
|
|
return
|
|
} else if (attempts < maxAttempts) {
|
|
await page.waitForTimeout(wait)
|
|
return pollUntilCondition(page, fn, wait, attempts + 1, maxAttempts)
|
|
} else {
|
|
throw new Error('Max attempts reached without condition being true')
|
|
}
|
|
}
|