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)
77 lines
2.5 KiB
TypeScript
77 lines
2.5 KiB
TypeScript
import { expect, test, WindowWithInsights } from './utils/insights-playwright-test-base'
|
|
import { start } from './utils/setup'
|
|
import { BeforeSendFn } from '@/types'
|
|
|
|
const startOptions = {
|
|
options: {
|
|
session_recording: {},
|
|
},
|
|
flagsResponseOverrides: {
|
|
sessionRecording: {
|
|
endpoint: '/ses/',
|
|
},
|
|
capturePerformance: true,
|
|
},
|
|
url: '/playground/cypress-full/index.html',
|
|
}
|
|
|
|
test.describe('before_send', () => {
|
|
test('can sample and edit with before_send', async ({ page, context }) => {
|
|
await start(startOptions, page, context)
|
|
|
|
await page.evaluate(() => {
|
|
const insights = (window as WindowWithInsights).insights
|
|
if (!insights) {
|
|
throw new Error('Insights is not initialized')
|
|
}
|
|
let counter = 0
|
|
// box the original before_send function
|
|
const og: BeforeSendFn[] = Array.isArray(insights.config.before_send)
|
|
? insights.config.before_send
|
|
: insights.config.before_send !== undefined
|
|
? [insights.config.before_send]
|
|
: []
|
|
|
|
insights.config.before_send = [
|
|
(cr) => {
|
|
if (!cr) {
|
|
return null
|
|
}
|
|
|
|
if (cr.event === 'custom-event') {
|
|
counter++
|
|
if (counter === 2) {
|
|
return null
|
|
}
|
|
}
|
|
if (cr.event === '$autocapture') {
|
|
return {
|
|
...cr,
|
|
event: 'redacted',
|
|
}
|
|
}
|
|
return cr
|
|
},
|
|
// these tests rely on existing before_send function to capture events
|
|
// so we have to add it back in here
|
|
...og,
|
|
]
|
|
})
|
|
|
|
await page.locator('[data-cy-custom-event-button]').click()
|
|
await page.locator('[data-cy-custom-event-button]').click()
|
|
|
|
const captures = (await page.capturedEvents()).map((x) => x.event)
|
|
|
|
expect(captures).toEqual([
|
|
// before adding the new before sendfn
|
|
'$pageview',
|
|
'redacted',
|
|
'custom-event',
|
|
// second button click only has the redacted autocapture event
|
|
'redacted',
|
|
// because the second custom-event is rejected
|
|
])
|
|
})
|
|
})
|