-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
no need to start with very large test files
- Loading branch information
1 parent
6236863
commit be6e7c2
Showing
4 changed files
with
302 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { expect, test, WindowWithPostHog } from './utils/posthog-playwright-test-base' | ||
import { start } from './utils/setup' | ||
|
||
const startOptions = { | ||
options: { | ||
session_recording: {}, | ||
}, | ||
decideResponseOverrides: { | ||
sessionRecording: { | ||
endpoint: '/ses/', | ||
}, | ||
capturePerformance: true, | ||
autocapture_opt_out: true, | ||
}, | ||
url: './playground/cypress-full/index.html', | ||
} | ||
|
||
test.describe('session recording in array.full.js', () => { | ||
test('captures session events', async ({ page, context }) => { | ||
await start(startOptions, page, context) | ||
|
||
const responsePromise = page.waitForResponse('**/ses/*') | ||
await page.locator('[data-cy-input]').fill('hello posthog!') | ||
await responsePromise | ||
|
||
await page.evaluate(() => { | ||
const ph = (window as WindowWithPostHog).posthog | ||
ph?.capture('test_registered_property') | ||
}) | ||
|
||
const capturedEvents = await page.capturedEvents() | ||
expect(capturedEvents.map((x) => x.event)).toEqual(['$pageview', '$snapshot', 'test_registered_property']) | ||
|
||
// don't care about network payloads here | ||
const snapshotData = capturedEvents[1]['properties']['$snapshot_data'].filter((s: any) => s.type !== 6) | ||
|
||
// a meta and then a full snapshot | ||
expect(snapshotData[0].type).toEqual(4) // meta | ||
expect(snapshotData[1].type).toEqual(2) // full_snapshot | ||
expect(snapshotData[2].type).toEqual(5) // custom event with remote config | ||
expect(snapshotData[3].type).toEqual(5) // custom event with options | ||
expect(snapshotData[4].type).toEqual(5) // custom event with posthog config | ||
// Making a set from the rest should all be 3 - incremental snapshots | ||
const incrementalSnapshots = snapshotData.slice(5) | ||
expect(Array.from(new Set(incrementalSnapshots.map((s: any) => s.type)))).toStrictEqual([3]) | ||
|
||
expect(capturedEvents[2]['properties']['$session_recording_start_reason']).toEqual('recording_initialized') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { test } from './utils/posthog-playwright-test-base' | ||
|
||
test.describe('Session recording - array.js', () => { | ||
test.fixme('network capture', () => {}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { expect, test, WindowWithPostHog } from './utils/posthog-playwright-test-base' | ||
import { start } from './utils/setup' | ||
|
||
const startOptions = { | ||
options: { | ||
session_recording: {}, | ||
}, | ||
decideResponseOverrides: { | ||
sessionRecording: { | ||
endpoint: '/ses/', | ||
}, | ||
capturePerformance: true, | ||
autocapture_opt_out: true, | ||
}, | ||
url: './playground/cypress/index.html', | ||
} | ||
|
||
test.describe('Session recording - sampling', () => { | ||
const sampleZeroStartOptions = { | ||
...startOptions, | ||
decideResponseOverrides: { | ||
...startOptions.decideResponseOverrides, | ||
sessionRecording: { | ||
...startOptions.decideResponseOverrides.sessionRecording, | ||
sampleRate: '0', | ||
}, | ||
}, | ||
} | ||
test.beforeEach(async ({ page, context }) => { | ||
await start(startOptions, page, context) | ||
|
||
await page.waitForResponse('**/recorder.js*') | ||
const capturedEvents = await page.evaluate(() => (window as WindowWithPostHog).capturedEvents || []) | ||
expect(capturedEvents.map((x) => x.event)).toEqual(['$pageview']) | ||
await page.resetCapturedEvents() | ||
}) | ||
|
||
test('does not capture events when sampling is set to 0', async ({ page }) => { | ||
await page.locator('[data-cy-input]').fill('hello posthog!') | ||
// because it doesn't make sense to wait for a snapshot event that won't happen | ||
await page.waitForTimeout(250) | ||
|
||
const capturedEvents = await page.capturedEvents() | ||
expect(capturedEvents).toEqual([]) | ||
}) | ||
|
||
test('can override sampling when starting session recording', async ({ page, context }) => { | ||
await page.evaluate(() => { | ||
const ph = (window as WindowWithPostHog).posthog | ||
ph?.startSessionRecording({ sampling: true }) | ||
ph?.capture('test_registered_property') | ||
}) | ||
const capturedEvents = await page.capturedEvents() | ||
expect(capturedEvents.map((x) => x.event)).toEqual(['test_registered_property']) | ||
expect(capturedEvents[0]['properties']['$session_recording_start_reason']).toEqual('sampling_overridden') | ||
|
||
// sampling override survives a page refresh | ||
await page.resetCapturedEvents() | ||
await page.reload() | ||
|
||
await start( | ||
{ | ||
...sampleZeroStartOptions, | ||
type: 'reload', | ||
}, | ||
page, | ||
context | ||
) | ||
await page.waitForResponse('**/recorder.js*') | ||
const responsePromise = page.waitForResponse('**/ses/*') | ||
await page.locator('[data-cy-input]').fill('hello posthog!') | ||
await responsePromise | ||
|
||
const afterReloadCapturedEvents = await page.capturedEvents() | ||
const lastCaptured = afterReloadCapturedEvents[afterReloadCapturedEvents.length - 1] | ||
expect(lastCaptured['event']).toEqual('$snapshot') | ||
}) | ||
}) |
Oops, something went wrong.