Skip to content

Commit

Permalink
port all the capture spec without getting them passing
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra committed Jan 3, 2025
1 parent ea844f5 commit 2056a9b
Show file tree
Hide file tree
Showing 5 changed files with 345 additions and 431 deletions.
198 changes: 0 additions & 198 deletions cypress/e2e/capture.cy.ts

This file was deleted.

145 changes: 145 additions & 0 deletions playwright/autocapture-config.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import { test } from './utils/posthog-playwright-test-base'
import { start } from './utils/setup'

const startOptions = {
options: {},
decideResponseOverrides: {
sessionRecording: {
endpoint: '/ses/',
},
capturePerformance: true,
},
url: './playground/cypress/index.html',
}

test.describe('autocapture config', () => {
test('do not capture click if not in allowlist', async ({ page, context }) => {
await start(
{
...startOptions,
options: {
...startOptions.options,
capture_pageview: false,
autocapture: {
dom_event_allowlist: ['change'],
},
},
},
page,
context
)

await page.locator('[data-cy-custom-event-button]').click()
// no autocapture event from click
await page.expectCapturedEventsToBe(['custom-event'])

await page.locator('[data-cy-input]').fill('hello posthog!')
// blur the input
await page.locator('body').click()
await page.expectCapturedEventsToBe(['custom-event', '$autocapture'])
})

test('capture clicks when configured to', async ({ page, context }) => {
await start(
{
...startOptions,
options: { ...startOptions.options, autocapture: { dom_event_allowlist: ['click'] } },
},
page,
context
)

await page.locator('[data-cy-custom-event-button]').click()
await page.expectCapturedEventsToBe(['$pageview', '$autocapture', 'custom-event'])

await page.locator('[data-cy-input]').fill('hello posthog!')
// blur the input
await page.locator('body').click()
// no change autocapture event
await page.expectCapturedEventsToBe(['$pageview', '$autocapture', 'custom-event'])
})

test('obeys url allowlist', async ({ page, context }) => {
await start(
{
...startOptions,
options: { ...startOptions.options, autocapture: { url_allowlist: ['.*test-is-not-on-this.*'] } },
},
page,
context
)

await page.locator('[data-cy-custom-event-button]').click()
await page.expectCapturedEventsToBe(['$pageview', 'custom-event'])

await page.resetCapturedEvents()
await start(
{
...startOptions,
options: { ...startOptions.options, autocapture: { url_allowlist: ['.*cypress.*'] } },
},
page,
context
)

await page.locator('[data-cy-custom-event-button]').click()
await page.expectCapturedEventsToBe(['$pageview', '$autocapture', 'custom-event'])
})

test('obeys element allowlist', async ({ page, context }) => {
await start(
{
...startOptions,
options: { ...startOptions.options, autocapture: { element_allowlist: ['button'] } },
},
page,
context
)

await page.locator('[data-cy-custom-event-button]').click()
await page.expectCapturedEventsToBe(['$pageview', '$autocapture', 'custom-event'])

await page.resetCapturedEvents()
await start(
{
...startOptions,
options: { ...startOptions.options, autocapture: { element_allowlist: ['input'] } },
},
page,
context
)

await page.locator('[data-cy-custom-event-button]').click()
await page.expectCapturedEventsToBe(['$pageview', 'custom-event'])
})

test('obeys css selector allowlist', async ({ page, context }) => {
await start(
{
...startOptions,
options: {
...startOptions.options,
autocapture: { css_selector_allowlist: ['[data-cy-custom-event-button]'] },
},
},
page,
context
)

await page.locator('[data-cy-custom-event-button]').click()
await page.expectCapturedEventsToBe(['$pageview', '$autocapture', 'custom-event'])

await page.resetCapturedEvents()
await start(
{
...startOptions,
options: { ...startOptions.options, autocapture: { css_selector_allowlist: ['[data-cy-input]'] } },
},
page,
context
)

await page.locator('[data-cy-custom-event-button]').click()
await page.expectCapturedEventsToBe(['$pageview', 'custom-event'])
})
})
Loading

0 comments on commit 2056a9b

Please sign in to comment.