-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtest.ts
More file actions
219 lines (191 loc) · 6.93 KB
/
test.ts
File metadata and controls
219 lines (191 loc) · 6.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import { expect } from '@playwright/test';
import { sentryTest } from '../../../utils/fixtures';
import {
expectedClickBreadcrumb,
expectedCLSPerformanceSpan,
expectedFCPPerformanceSpan,
expectedFPPerformanceSpan,
expectedLCPPerformanceSpan,
expectedMemoryPerformanceSpan,
expectedNavigationPerformanceSpan,
getExpectedReplayEvent,
} from '../../../utils/replayEventTemplates';
import type { PerformanceSpan } from '../../../utils/replayHelpers';
import {
getCustomRecordingEvents,
getReplayEvent,
getReplayRecordingContent,
shouldSkipReplayTest,
waitForReplayRequest,
} from '../../../utils/replayHelpers';
sentryTest(
'replay recording should contain default performance spans',
async ({ getLocalTestUrl, page, browserName }) => {
// We only test this against the NPM package and replay bundles
// and only on chromium as most performance entries are only available in chromium
if (shouldSkipReplayTest() || browserName !== 'chromium') {
sentryTest.skip();
}
const reqPromise0 = waitForReplayRequest(page, 0);
const reqPromise1 = waitForReplayRequest(page, 1);
const url = await getLocalTestUrl({ testDir: __dirname });
await page.goto(url);
const replayEvent0 = getReplayEvent(await reqPromise0);
const { performanceSpans: performanceSpans0 } = getCustomRecordingEvents(await reqPromise0);
expect(replayEvent0).toEqual(getExpectedReplayEvent({ segment_id: 0 }));
await page.locator('#img-button').click();
const replayEvent1 = getReplayEvent(await reqPromise1);
const { performanceSpans: performanceSpans1 } = getCustomRecordingEvents(await reqPromise1);
expect(replayEvent1).toEqual(getExpectedReplayEvent({ segment_id: 1, urls: [] }));
// We can't guarantee the order of the performance spans, or in which of the two segments they are sent
// So to avoid flakes, we collect them all and check that they are all there
const collectedPerformanceSpans = [...performanceSpans0, ...performanceSpans1];
expect(collectedPerformanceSpans).toEqual(
expect.arrayContaining([
expectedNavigationPerformanceSpan,
expectedLCPPerformanceSpan,
expectedCLSPerformanceSpan,
expectedFPPerformanceSpan,
expectedFCPPerformanceSpan,
expectedMemoryPerformanceSpan, // two memory spans - once per flush
expectedMemoryPerformanceSpan,
]),
);
const lcpSpan = collectedPerformanceSpans.find(
s => s.description === 'largest-contentful-paint',
) as PerformanceSpan;
// LCP spans should be point-in-time spans
expect(lcpSpan?.startTimestamp).toBeCloseTo(lcpSpan?.endTimestamp);
},
);
sentryTest(
'replay recording should contain a click breadcrumb when a button is clicked',
async ({ forceFlushReplay, getLocalTestUrl, page, browserName }) => {
// TODO(replay): This is flakey on webkit where clicks are flakey
if (shouldSkipReplayTest() || browserName === 'webkit') {
sentryTest.skip();
}
const reqPromise0 = waitForReplayRequest(page, 0);
const reqPromise1 = waitForReplayRequest(page, 1);
const reqPromise2 = waitForReplayRequest(page, 2);
const reqPromise3 = waitForReplayRequest(page, 3);
const url = await getLocalTestUrl({ testDir: __dirname });
await page.goto(url);
await reqPromise0;
await page.locator('#error').click();
await forceFlushReplay();
const req1 = await reqPromise1;
const content1 = getReplayRecordingContent(req1);
expect(content1.breadcrumbs).toEqual(
expect.arrayContaining([
{
...expectedClickBreadcrumb,
message: 'body > div#error.btn.btn-error[aria-label="An Error in aria-label"]',
data: {
nodeId: expect.any(Number),
node: {
attributes: {
'aria-label': '** ***** ** **********',
class: 'btn btn-error',
id: 'error',
role: 'button',
},
id: expect.any(Number),
tagName: 'div',
textContent: '** *****',
},
},
},
]),
);
await page.locator('#img').click();
await forceFlushReplay();
const req2 = await reqPromise2;
const content2 = getReplayRecordingContent(req2);
expect(content2.breadcrumbs).toEqual(
expect.arrayContaining([
{
...expectedClickBreadcrumb,
message: 'body > button#img-button[title="Button title"]',
data: {
nodeId: expect.any(Number),
node: {
attributes: {
id: 'img-button',
title: '****** *****',
},
id: expect.any(Number),
tagName: 'button',
textContent: '',
},
},
},
]),
);
await page.locator('.sentry-unmask').click();
await forceFlushReplay();
const req3 = await reqPromise3;
const content3 = getReplayRecordingContent(req3);
expect(content3.breadcrumbs).toEqual(
expect.arrayContaining([
{
...expectedClickBreadcrumb,
message: 'body > button.sentry-unmask[aria-label="Unmasked label"]',
data: {
nodeId: expect.any(Number),
node: {
attributes: {
'aria-label': 'Unmasked label',
class: 'sentry-unmask',
},
id: expect.any(Number),
tagName: 'button',
textContent: 'Unmasked',
},
},
},
]),
);
},
);
sentryTest(
'replay recording should contain an "options" breadcrumb for Replay SDK configuration',
async ({ forceFlushReplay, getLocalTestUrl, page, browserName }) => {
// TODO(replay): This is flakey on webkit where clicks are flakey
if (shouldSkipReplayTest() || browserName === 'webkit') {
sentryTest.skip();
}
const reqPromise0 = waitForReplayRequest(page, 0);
const reqPromise1 = waitForReplayRequest(page, 1);
const url = await getLocalTestUrl({ testDir: __dirname });
await page.goto(url);
await forceFlushReplay();
await page.locator('#error').click();
await forceFlushReplay();
const req0 = await reqPromise0;
const content0 = getReplayRecordingContent(req0);
expect(content0.optionsEvents).toEqual([
{
tag: 'options',
payload: {
sessionSampleRate: 1,
errorSampleRate: 0,
useCompressionOption: false,
blockAllMedia: false,
maskAllText: true,
maskAllInputs: true,
useCompression: false,
networkDetailHasUrls: false,
networkCaptureBodies: true,
networkRequestHasHeaders: true,
networkResponseHasHeaders: true,
shouldRecordCanvas: false,
},
},
]);
const req1 = await reqPromise1;
const content1 = getReplayRecordingContent(req1);
// Should only be on first segment
expect(content1.optionsEvents).toEqual([]);
},
);