mirror of
https://github.com/hanzoai/insights-js.git
synced 2026-11-03 00:53:53 +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)
105 lines
3.6 KiB
TypeScript
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()
|
|
}
|
|
})
|
|
})
|
|
})
|