Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(ci): move more of the browser tests to playwright #1638

Merged
merged 19 commits into from
Jan 5, 2025
Merged
Prev Previous commit
Next Next commit
fix one
pauldambra committed Jan 5, 2025
commit 65af1b0fe2fd4ca5e84fefbfd13e63295f7639fe
15 changes: 9 additions & 6 deletions playwright/capture.spec.ts
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ import { decompressSync, strFromU8 } from 'fflate'
function getGzipEncodedPayloady(req: Request): Record<string, any> {
const data = req.postDataBuffer()
if (!data) {
//console.log('wat', req.postData())
throw new Error('Expected body to be present')
}
const decoded = strFromU8(decompressSync(data))
@@ -38,11 +37,11 @@ test.describe('event capture', () => {
await page.expectCapturedEventsToBe(['$pageview', '$autocapture', 'custom-event', '$pageleave', '$pageview'])
})

test('contains the correct payload after an event', async ({ page, context }) => {
test('contains the correct payload after an event', async ({ page, context, browserName }) => {
const captureRequests: Request[] = []

page.on('request', (request) => {
if (request.url().includes('/e/')) {
if (request.url().includes('/e/') && request.method() === 'POST') {
captureRequests.push(request)
}
})
@@ -55,9 +54,13 @@ test.describe('event capture', () => {
const captureRequest = captureRequests[0]
expect(captureRequest.headers()['content-type']).toEqual('text/plain')
expect(captureRequest.url()).toMatch(/gzip/)
const payload = getGzipEncodedPayloady(captureRequest)
expect(payload.event).toEqual('$pageview')
expect(Object.keys(payload.properties).length).toBeGreaterThan(0)
// webkit doesn't allow us to read the body for some reason
// see e.g. https://github.com/microsoft/playwright/issues/6479
if (browserName !== 'webkit') {
const payload = getGzipEncodedPayloady(captureRequest)
expect(payload.event).toEqual('$pageview')
expect(Object.keys(payload.properties).length).toBeGreaterThan(0)
}
})

test('captures $feature_flag_called event', async ({ page, context }) => {
9 changes: 8 additions & 1 deletion playwright/utils/posthog-playwright-test-base.ts
Original file line number Diff line number Diff line change
@@ -78,6 +78,11 @@ export const test = base.extend<{ mockStaticAssets: void; page: Page }>({
status: 200,
contentType: 'application/json',
body: JSON.stringify({ status: 1 }),
headers: {
'Access-Control-Allow-Headers': '*',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': 'true',
},
})
})

@@ -92,7 +97,9 @@ export const test = base.extend<{ mockStaticAssets: void; page: Page }>({
lazyLoadedJSFiles.forEach((key: string) => {
void context.route(new RegExp(`^.*/static/${key}\\.js(\\?.*)?$`), (route) => {
route.fulfill({
headers: { loaded: 'using relative path by playwright' },
headers: {
loaded: 'using relative path by playwright',
},
path: `./dist/${key}.js`,
})
})