|
| 1 | +/* eslint-disable @typescript-eslint/explicit-function-return-type */ |
| 2 | +import { expect } from '@playwright/test'; |
| 3 | +import { SDK_VERSION } from '@sentry/browser'; |
| 4 | +import type { ReplayEvent } from '@sentry/types'; |
| 5 | + |
| 6 | +const DEFAULT_REPLAY_EVENT = { |
| 7 | + type: 'replay_event', |
| 8 | + timestamp: expect.any(Number), |
| 9 | + error_ids: [], |
| 10 | + trace_ids: [], |
| 11 | + urls: [expect.stringContaining('/dist/index.html')], |
| 12 | + replay_id: expect.stringMatching(/\w{32}/), |
| 13 | + replay_start_timestamp: expect.any(Number), |
| 14 | + segment_id: 0, |
| 15 | + replay_type: 'session', |
| 16 | + event_id: expect.stringMatching(/\w{32}/), |
| 17 | + environment: 'production', |
| 18 | + sdk: { |
| 19 | + integrations: [ |
| 20 | + 'InboundFilters', |
| 21 | + 'FunctionToString', |
| 22 | + 'TryCatch', |
| 23 | + 'Breadcrumbs', |
| 24 | + 'GlobalHandlers', |
| 25 | + 'LinkedErrors', |
| 26 | + 'Dedupe', |
| 27 | + 'HttpContext', |
| 28 | + 'Replay', |
| 29 | + ], |
| 30 | + version: SDK_VERSION, |
| 31 | + name: 'sentry.javascript.browser', |
| 32 | + }, |
| 33 | + sdkProcessingMetadata: {}, |
| 34 | + request: { |
| 35 | + url: expect.stringContaining('/dist/index.html'), |
| 36 | + headers: { |
| 37 | + 'User-Agent': expect.stringContaining(''), |
| 38 | + }, |
| 39 | + }, |
| 40 | + platform: 'javascript', |
| 41 | + contexts: { replay: { session_sample_rate: 1, error_sample_rate: 0 } }, |
| 42 | +}; |
| 43 | + |
| 44 | +/** |
| 45 | + * Creates a ReplayEvent object with the default values merged with the customExpectedReplayEvent. |
| 46 | + * This is useful for testing multi-segment replays to not repeat most of the properties that don't change |
| 47 | + * throughout the replay segments. |
| 48 | + * |
| 49 | + * Note: The benfit of this approach over expect.objectContaining is that, |
| 50 | + * we'll catch if properties we expect to stay the same actually change. |
| 51 | + * |
| 52 | + * @param customExpectedReplayEvent overwrite the default values with custom values (e.g. segment_id) |
| 53 | + */ |
| 54 | +export function getExpectedReplayEvent(customExpectedReplayEvent: Partial<ReplayEvent> & Record<string, unknown> = {}) { |
| 55 | + return { |
| 56 | + ...DEFAULT_REPLAY_EVENT, |
| 57 | + ...customExpectedReplayEvent, |
| 58 | + }; |
| 59 | +} |
| 60 | + |
| 61 | +/* This is how we expect different kinds of navigation performance span to look: */ |
| 62 | + |
| 63 | +export const expectedNavigationPerformanceSpan = { |
| 64 | + op: 'navigation.navigate', |
| 65 | + description: '', |
| 66 | + startTimestamp: expect.any(Number), |
| 67 | + endTimestamp: expect.any(Number), |
| 68 | + data: { |
| 69 | + duration: expect.any(Number), |
| 70 | + size: expect.any(Number), |
| 71 | + }, |
| 72 | +}; |
| 73 | + |
| 74 | +export const expectedMemoryPerformanceSpan = { |
| 75 | + op: 'memory', |
| 76 | + description: 'memory', |
| 77 | + startTimestamp: expect.any(Number), |
| 78 | + endTimestamp: expect.any(Number), |
| 79 | + data: { |
| 80 | + memory: { |
| 81 | + jsHeapSizeLimit: expect.any(Number), |
| 82 | + totalJSHeapSize: expect.any(Number), |
| 83 | + usedJSHeapSize: expect.any(Number), |
| 84 | + }, |
| 85 | + }, |
| 86 | +}; |
| 87 | + |
| 88 | +export const expectedLCPPerformanceSpan = { |
| 89 | + op: 'largest-contentful-paint', |
| 90 | + description: 'largest-contentful-paint', |
| 91 | + startTimestamp: expect.any(Number), |
| 92 | + endTimestamp: expect.any(Number), |
| 93 | + data: { |
| 94 | + duration: expect.any(Number), |
| 95 | + nodeId: expect.any(Number), |
| 96 | + size: expect.any(Number), |
| 97 | + }, |
| 98 | +}; |
| 99 | + |
| 100 | +export const expectedFCPPerformanceSpan = { |
| 101 | + op: 'paint', |
| 102 | + description: 'first-contentful-paint', |
| 103 | + startTimestamp: expect.any(Number), |
| 104 | + endTimestamp: expect.any(Number), |
| 105 | +}; |
| 106 | + |
| 107 | +export const expectedFPPerformanceSpan = { |
| 108 | + op: 'paint', |
| 109 | + description: 'first-paint', |
| 110 | + startTimestamp: expect.any(Number), |
| 111 | + endTimestamp: expect.any(Number), |
| 112 | +}; |
0 commit comments