Files
zeekay d57cb038bd chore: rename all PostHog references to Insights/Hanzo
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)
2026-03-06 01:41:12 -08:00

105 lines
3.6 KiB
TypeScript

import { expect, test } from './utils/insights-playwright-test-base'
import { start } from './utils/setup'
import { pollUntilEventCaptured } from './utils/event-capture-utils'
const startOptions = {
options: {
capture_performance: {
web_vitals: true,
},
},
flagsResponseOverrides: {
capturePerformance: true,
},
url: '/playground/cypress/index.html',
}
test.describe('Web Vitals', () => {
test('captures web vitals events when enabled', async ({ page, context }) => {
await start(startOptions, page, context)
// Wait for web vitals events to be captured
await pollUntilEventCaptured(page, '$web_vitals')
const webVitalsEvents = (await page.capturedEvents()).filter((event) => event.event === '$web_vitals')
expect(webVitalsEvents.length).toBeGreaterThan(0)
const webVitalsEvent = webVitalsEvents[0]
// will always get the FCP event on this bot browser but not necessarily the others
expect(webVitalsEvent.properties).toMatchObject({
$current_url: expect.any(String),
$session_id: expect.any(String),
$window_id: expect.any(String),
$web_vitals_FCP_value: expect.any(Number),
})
expect(webVitalsEvent.properties.$web_vitals_FCP_event).toMatchObject({
name: 'FCP',
value: expect.any(Number),
$current_url: expect.any(String),
$session_id: expect.any(String),
$window_id: expect.any(String),
timestamp: expect.any(Number),
})
})
test('does not capture web vitals when disabled', async ({ page, context }) => {
await start(
{
...startOptions,
options: {
capture_performance: {
web_vitals: false,
},
},
},
page,
context
)
// Wait a bit to ensure no web vitals events are captured
await page.waitForTimeout(5000)
const webVitalsEvents = (await page.capturedEvents()).filter((event) => event.event === '$web_vitals')
expect(webVitalsEvents.length).toBe(0)
})
;[
{ attributionConfig: true, shouldHaveAttribution: true },
{ attributionConfig: false, shouldHaveAttribution: false },
{ attributionConfig: undefined, shouldHaveAttribution: false },
].forEach(({ attributionConfig, shouldHaveAttribution }) => {
test(`web_vitals_attribution: ${attributionConfig} ${shouldHaveAttribution ? 'includes' : 'excludes'} attribution data`, async ({
page,
context,
}) => {
await start(
{
...startOptions,
options: {
capture_performance: {
web_vitals: true,
web_vitals_attribution: attributionConfig,
},
},
},
page,
context
)
await pollUntilEventCaptured(page, '$web_vitals')
const webVitalsEvents = (await page.capturedEvents()).filter((event) => event.event === '$web_vitals')
expect(webVitalsEvents.length).toBeGreaterThan(0)
const fcpEvent = webVitalsEvents[0].properties.$web_vitals_FCP_event
expect(fcpEvent).toBeDefined()
if (shouldHaveAttribution) {
expect(fcpEvent.attribution).toBeDefined()
} else {
expect(fcpEvent.attribution).toBeUndefined()
}
})
})
})