|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | +import { SDK_VERSION } from '@sentry/browser'; |
| 3 | +import type { Event } from '@sentry/types'; |
| 4 | + |
| 5 | +import { sentryTest } from '../../../utils/fixtures'; |
| 6 | +import { getFirstSentryEnvelopeRequest } from '../../../utils/helpers'; |
| 7 | + |
| 8 | +sentryTest('captureReplay', async ({ getLocalTestPath, page }) => { |
| 9 | + // For this test, we skip all bundle tests, as we're only interested in Replay being correctly |
| 10 | + // exported from the `@sentry/browser` npm package. |
| 11 | + if (process.env.PW_BUNDLE && process.env.PW_BUNDLE.startsWith('bundle_')) { |
| 12 | + sentryTest.skip(); |
| 13 | + } |
| 14 | + |
| 15 | + await page.route('https://dsn.ingest.sentry.io/**/*', route => { |
| 16 | + return route.fulfill({ |
| 17 | + status: 200, |
| 18 | + contentType: 'application/json', |
| 19 | + body: JSON.stringify({ id: 'test-id' }), |
| 20 | + }); |
| 21 | + }); |
| 22 | + |
| 23 | + const url = await getLocalTestPath({ testDir: __dirname }); |
| 24 | + await page.goto(url); |
| 25 | + |
| 26 | + await page.click('button'); |
| 27 | + await page.waitForTimeout(300); |
| 28 | + |
| 29 | + const replayEvent = await getFirstSentryEnvelopeRequest<Event>(page, url); |
| 30 | + |
| 31 | + expect(replayEvent).toBeDefined(); |
| 32 | + expect(replayEvent).toEqual({ |
| 33 | + type: 'replay_event', |
| 34 | + timestamp: expect.any(Number), |
| 35 | + error_ids: [], |
| 36 | + trace_ids: [], |
| 37 | + urls: [expect.stringContaining('/dist/index.html')], |
| 38 | + replay_id: expect.stringMatching(/\w{32}/), |
| 39 | + segment_id: 2, |
| 40 | + replay_type: 'session', |
| 41 | + event_id: expect.stringMatching(/\w{32}/), |
| 42 | + environment: 'production', |
| 43 | + sdk: { |
| 44 | + integrations: [ |
| 45 | + 'InboundFilters', |
| 46 | + 'FunctionToString', |
| 47 | + 'TryCatch', |
| 48 | + 'Breadcrumbs', |
| 49 | + 'GlobalHandlers', |
| 50 | + 'LinkedErrors', |
| 51 | + 'Dedupe', |
| 52 | + 'HttpContext', |
| 53 | + 'Replay', |
| 54 | + ], |
| 55 | + version: SDK_VERSION, |
| 56 | + name: 'sentry.javascript.browser', |
| 57 | + }, |
| 58 | + sdkProcessingMetadata: {}, |
| 59 | + request: { |
| 60 | + url: expect.stringContaining('/dist/index.html'), |
| 61 | + headers: { |
| 62 | + 'User-Agent': expect.stringContaining(''), |
| 63 | + }, |
| 64 | + }, |
| 65 | + platform: 'javascript', |
| 66 | + tags: { sessionSampleRate: 1, errorSampleRate: 0 }, |
| 67 | + }); |
| 68 | +}); |
0 commit comments