|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | +import fs from 'fs'; |
| 3 | +import path from 'path'; |
| 4 | + |
| 5 | +import { sentryTest, TEST_HOST } from '../../../utils/fixtures'; |
| 6 | +import { getExpectedReplayEvent } from '../../../utils/replayEventTemplates'; |
| 7 | +import { |
| 8 | + getFullRecordingSnapshots, |
| 9 | + getReplayEvent, |
| 10 | + replayEnvelopeIsCompressed, |
| 11 | + shouldSkipReplayTest, |
| 12 | + waitForReplayRequest, |
| 13 | +} from '../../../utils/replayHelpers'; |
| 14 | + |
| 15 | +sentryTest( |
| 16 | + 'replay recording should be compressed if using custom workerUrl', |
| 17 | + async ({ getLocalTestUrl, page, forceFlushReplay }) => { |
| 18 | + if (shouldSkipReplayTest()) { |
| 19 | + sentryTest.skip(); |
| 20 | + } |
| 21 | + |
| 22 | + const reqPromise0 = waitForReplayRequest(page, 0); |
| 23 | + |
| 24 | + await page.route('https://dsn.ingest.sentry.io/**/*', route => { |
| 25 | + return route.fulfill({ |
| 26 | + status: 200, |
| 27 | + contentType: 'application/json', |
| 28 | + body: JSON.stringify({ id: 'test-id' }), |
| 29 | + }); |
| 30 | + }); |
| 31 | + |
| 32 | + const url = await getLocalTestUrl({ testDir: __dirname }); |
| 33 | + |
| 34 | + let customCompressCalled = 0; |
| 35 | + |
| 36 | + // Ensure to register this _after_ getLocalTestUrl is called, as that also registers a default route for TEST_HOST |
| 37 | + await page.route(`${TEST_HOST}/my-test-worker.js`, route => { |
| 38 | + const filePath = path.resolve(__dirname, '../../../../replay-worker/examples/worker.min.js'); |
| 39 | + |
| 40 | + customCompressCalled++; |
| 41 | + |
| 42 | + return fs.existsSync(filePath) ? route.fulfill({ path: filePath }) : route.continue(); |
| 43 | + }); |
| 44 | + |
| 45 | + await page.goto(url); |
| 46 | + await forceFlushReplay(); |
| 47 | + |
| 48 | + const req0 = await reqPromise0; |
| 49 | + |
| 50 | + const replayEvent0 = getReplayEvent(req0); |
| 51 | + expect(replayEvent0).toEqual(getExpectedReplayEvent()); |
| 52 | + |
| 53 | + expect(replayEnvelopeIsCompressed(req0)).toEqual(true); |
| 54 | + expect(customCompressCalled).toBe(1); |
| 55 | + |
| 56 | + const snapshots = getFullRecordingSnapshots(req0); |
| 57 | + expect(snapshots.length).toEqual(1); |
| 58 | + |
| 59 | + const stringifiedSnapshot = JSON.stringify(snapshots[0]); |
| 60 | + expect(stringifiedSnapshot).toContain('"tagName":"body"'); |
| 61 | + expect(stringifiedSnapshot).toContain('"tagName":"html"'); |
| 62 | + expect(stringifiedSnapshot).toContain('"tagName":"button"'); |
| 63 | + expect(stringifiedSnapshot).toContain('"textContent":"*** ***"'); |
| 64 | + expect(stringifiedSnapshot).toContain('"id":"go-background"'); |
| 65 | + }, |
| 66 | +); |
0 commit comments