Skip to content

Commit 32a774b

Browse files
committed
update tests and refactor
1 parent 6e29bcc commit 32a774b

File tree

8 files changed

+108
-123
lines changed

8 files changed

+108
-123
lines changed

dev-packages/browser-integration-tests/suites/replay/customEvents/test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import {
66
expectedFCPPerformanceSpan,
77
expectedFPPerformanceSpan,
88
expectedLCPPerformanceSpan,
9+
expectedCLSPerformanceSpan,
10+
expectedFIDPerformanceSpan,
11+
expectedINPPerformanceSpan,
912
expectedMemoryPerformanceSpan,
1013
expectedNavigationPerformanceSpan,
1114
getExpectedReplayEvent,
@@ -62,6 +65,9 @@ sentryTest(
6265
expect.arrayContaining([
6366
expectedNavigationPerformanceSpan,
6467
expectedLCPPerformanceSpan,
68+
expectedCLSPerformanceSpan,
69+
expectedFIDPerformanceSpan,
70+
expectedINPPerformanceSpan,
6571
expectedFPPerformanceSpan,
6672
expectedFCPPerformanceSpan,
6773
expectedMemoryPerformanceSpan, // two memory spans - once per flush

dev-packages/browser-integration-tests/suites/replay/multiple-pages/test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import {
66
expectedFCPPerformanceSpan,
77
expectedFPPerformanceSpan,
88
expectedLCPPerformanceSpan,
9+
expectedCLSPerformanceSpan,
10+
expectedFIDPerformanceSpan,
11+
expectedINPPerformanceSpan,
912
expectedMemoryPerformanceSpan,
1013
expectedNavigationBreadcrumb,
1114
expectedNavigationPerformanceSpan,
@@ -83,6 +86,9 @@ sentryTest(
8386
expect.arrayContaining([
8487
expectedNavigationPerformanceSpan,
8588
expectedLCPPerformanceSpan,
89+
expectedCLSPerformanceSpan,
90+
expectedFIDPerformanceSpan,
91+
expectedINPPerformanceSpan,
8692
expectedFPPerformanceSpan,
8793
expectedFCPPerformanceSpan,
8894
expectedMemoryPerformanceSpan, // two memory spans - once per flush
@@ -121,6 +127,9 @@ sentryTest(
121127
expect.arrayContaining([
122128
expectedReloadPerformanceSpan,
123129
expectedLCPPerformanceSpan,
130+
expectedCLSPerformanceSpan,
131+
expectedFIDPerformanceSpan,
132+
expectedINPPerformanceSpan,
124133
expectedFPPerformanceSpan,
125134
expectedFCPPerformanceSpan,
126135
expectedMemoryPerformanceSpan,
@@ -188,6 +197,9 @@ sentryTest(
188197
expect.arrayContaining([
189198
expectedNavigationPerformanceSpan,
190199
expectedLCPPerformanceSpan,
200+
expectedCLSPerformanceSpan,
201+
expectedFIDPerformanceSpan,
202+
expectedINPPerformanceSpan,
191203
expectedFPPerformanceSpan,
192204
expectedFCPPerformanceSpan,
193205
expectedMemoryPerformanceSpan,
@@ -309,6 +321,9 @@ sentryTest(
309321
expect.arrayContaining([
310322
expectedNavigationPerformanceSpan,
311323
expectedLCPPerformanceSpan,
324+
expectedCLSPerformanceSpan,
325+
expectedFIDPerformanceSpan,
326+
expectedINPPerformanceSpan,
312327
expectedFPPerformanceSpan,
313328
expectedFCPPerformanceSpan,
314329
expectedMemoryPerformanceSpan,

dev-packages/browser-integration-tests/utils/replayEventTemplates.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,46 @@ export const expectedLCPPerformanceSpan = {
128128
data: {
129129
value: expect.any(Number),
130130
nodeId: expect.any(Number),
131+
rating: expect.any(String),
132+
size: expect.any(Number),
133+
},
134+
};
135+
136+
export const expectedCLSPerformanceSpan = {
137+
op: 'web-vital',
138+
description: 'cumulative-layout-shift',
139+
startTimestamp: expect.any(Number),
140+
endTimestamp: expect.any(Number),
141+
data: {
142+
value: expect.any(Number),
143+
nodeId: expect.any(Number),
144+
rating: expect.any(String),
145+
size: expect.any(Number),
146+
},
147+
};
148+
149+
export const expectedFIDPerformanceSpan = {
150+
op: 'web-vital',
151+
description: 'first-input-delay',
152+
startTimestamp: expect.any(Number),
153+
endTimestamp: expect.any(Number),
154+
data: {
155+
value: expect.any(Number),
156+
nodeId: expect.any(Number),
157+
rating: expect.any(String),
158+
size: expect.any(Number),
159+
},
160+
};
161+
162+
export const expectedINPPerformanceSpan = {
163+
op: 'web-vital',
164+
description: 'interaction-to-next-paint',
165+
startTimestamp: expect.any(Number),
166+
endTimestamp: expect.any(Number),
167+
data: {
168+
value: expect.any(Number),
169+
nodeId: expect.any(Number),
170+
rating: expect.any(String),
131171
size: expect.any(Number),
132172
},
133173
};

dev-packages/e2e-tests/test-applications/react-router-6-use-routes/tests/fixtures/ReplayRecordingData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ export const ReplayRecordingData = [
212212
data: {
213213
tag: 'performanceSpan',
214214
payload: {
215-
op: 'largest-contentful-paint',
215+
op: 'web-vital',
216216
description: 'largest-contentful-paint',
217217
startTimestamp: expect.any(Number),
218218
endTimestamp: expect.any(Number),

packages/replay-internal/src/types/performance.ts

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -96,58 +96,27 @@ export type ResourceData = Pick<PerformanceResourceTiming, 'decodedBodySize' | '
9696
statusCode?: number;
9797
};
9898

99-
export interface LargestContentfulPaintData {
99+
export interface WebVitalData {
100100
/**
101101
* Render time (in ms) of the LCP
102102
*/
103103
value: number;
104104
size: number;
105105
/**
106-
* The recording id of the LCP node. -1 if not found
107-
*/
108-
nodeId?: number;
109-
}
110-
111-
export interface CumulativeLayoutShiftData {
112-
/**
113-
* Render time (in ms) of the CLS
114-
*/
115-
value: number;
116-
size: number;
117-
/**
118-
* The recording id of the CLS node. -1 if not found
106+
* The rating as to whether the metric value is within the "good",
107+
* "needs improvement", or "poor" thresholds of the metric.
119108
*/
120-
nodeId?: number;
121-
}
122-
123-
export interface FirstInputDelayData {
109+
rating: 'good' | 'needs-improvement' | 'poor';
124110
/**
125-
* Render time (in ms) of the FID
126-
*/
127-
value: number;
128-
size: number;
129-
/**
130-
* The recording id of the FID node. -1 if not found
131-
*/
132-
nodeId?: number;
133-
}
134-
135-
export interface InteractionToNextPaintData {
136-
/**
137-
* Render time (in ms) of the INP
138-
*/
139-
value: number;
140-
size: number;
141-
/**
142-
* The recording id of the INP node. -1 if not found
111+
* The recording id of the LCP node. -1 if not found
143112
*/
144113
nodeId?: number;
145114
}
146115

147116
/**
148117
* Entries that come from window.performance
149118
*/
150-
export type AllPerformanceEntryData = PaintData | NavigationData | ResourceData | LargestContentfulPaintData | CumulativeLayoutShiftData | FirstInputDelayData;
119+
export type AllPerformanceEntryData = PaintData | NavigationData | ResourceData | WebVitalData;
151120

152121
export interface MemoryData {
153122
memory: {

packages/replay-internal/src/types/replayFrame.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@ import type { Breadcrumb } from '@sentry/types';
22

33
import type {
44
HistoryData,
5-
LargestContentfulPaintData,
6-
CumulativeLayoutShiftData,
7-
FirstInputDelayData,
8-
InteractionToNextPaintData,
95
MemoryData,
106
NavigationData,
117
NetworkRequestData,
128
PaintData,
139
ResourceData,
10+
WebVitalData,
1411
} from './performance';
1512
import type { ReplayEventTypeCustom } from './rrweb';
1613

@@ -166,22 +163,22 @@ interface ReplayHistoryFrame extends ReplayBaseSpanFrame {
166163
}
167164

168165
interface ReplayLargestContentfulPaintFrame extends ReplayBaseSpanFrame {
169-
data: LargestContentfulPaintData;
166+
data: WebVitalData;
170167
op: 'largest-contentful-paint';
171168
}
172169

173170
interface ReplayCumulativeLayoutShiftFrame extends ReplayBaseSpanFrame {
174-
data: CumulativeLayoutShiftData;
171+
data: WebVitalData;
175172
op: 'cumulative-layout-shift';
176173
}
177174

178175
interface ReplayFirstInputDelayFrame extends ReplayBaseSpanFrame {
179-
data: FirstInputDelayData;
176+
data: WebVitalData;
180177
op: 'first-input-delay';
181178
}
182179

183180
interface ReplayInteractionToNextPaintFrame extends ReplayBaseSpanFrame {
184-
data: InteractionToNextPaintData;
181+
data: WebVitalData;
185182
op: 'interaction-to-next-paint';
186183
}
187184

packages/replay-internal/src/util/createPerformanceEntries.ts

Lines changed: 27 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@ import type {
66
AllPerformanceEntry,
77
AllPerformanceEntryData,
88
ExperimentalPerformanceResourceTiming,
9-
LargestContentfulPaintData,
10-
CumulativeLayoutShiftData,
11-
FirstInputDelayData,
12-
InteractionToNextPaintData,
139
NavigationData,
1410
PaintData,
1511
ReplayPerformanceEntry,
1612
ResourceData,
13+
WebVitalData,
1714
} from '../types';
1815

1916
// Map entryType -> function to normalize data for event
@@ -148,114 +145,71 @@ function createResourceEntry(
148145
*/
149146
export function getLargestContentfulPaint(metric: {
150147
value: number;
148+
rating: 'good' | 'needs-improvement' | 'poor';
151149
entries: PerformanceEntry[];
152-
}): ReplayPerformanceEntry<LargestContentfulPaintData> {
153-
const entries = metric.entries;
154-
const lastEntry = entries[entries.length - 1] as (PerformanceEntry & { element?: Element }) | undefined;
155-
const element = lastEntry ? lastEntry.element : undefined;
156-
157-
const value = metric.value;
158-
159-
const end = getAbsoluteTime(value);
160-
161-
const data: ReplayPerformanceEntry<LargestContentfulPaintData> = {
162-
type: 'web-vital',
163-
name: 'largest-contentful-paint',
164-
start: end,
165-
end,
166-
data: {
167-
value,
168-
size: value,
169-
nodeId: element ? record.mirror.getId(element) : undefined,
170-
},
171-
};
172-
173-
return data;
150+
}): ReplayPerformanceEntry<WebVitalData> {
151+
return getWebVital(metric, 'largest-contentful-paint');
174152
}
175153

176154
/**
177155
* Add a CLS event to the replay based on a CLS metric.
178156
*/
179157
export function getCumulativeLayoutShift(metric: {
180158
value: number;
159+
rating: 'good' | 'needs-improvement' | 'poor';
181160
entries: PerformanceEntry[];
182-
}): ReplayPerformanceEntry<CumulativeLayoutShiftData> {
183-
const entries = metric.entries;
184-
const lastEntry = entries[entries.length - 1] as (PerformanceEntry & { element?: Element }) | undefined;
185-
const element = lastEntry ? lastEntry.element : undefined;
186-
187-
const value = metric.value;
188-
189-
const end = getAbsoluteTime(value);
190-
191-
const data: ReplayPerformanceEntry<CumulativeLayoutShiftData> = {
192-
type: 'web-vital',
193-
name: 'cumulative-layout-shift',
194-
start: end,
195-
end,
196-
data: {
197-
value,
198-
size: value,
199-
nodeId: element ? record.mirror.getId(element) : undefined,
200-
},
201-
};
202-
203-
return data;
161+
}): ReplayPerformanceEntry<WebVitalData> {
162+
return getWebVital(metric, 'cumulative-layout-shift');
204163
}
205164

206165
/**
207166
* Add a FID event to the replay based on a FID metric.
208167
*/
209168
export function getFirstInputDelay(metric: {
210169
value: number;
170+
rating: 'good' | 'needs-improvement' | 'poor';
211171
entries: PerformanceEntry[];
212-
}): ReplayPerformanceEntry<FirstInputDelayData> {
213-
const entries = metric.entries;
214-
const lastEntry = entries[entries.length - 1] as (PerformanceEntry & { element?: Element }) | undefined;
215-
const element = lastEntry ? lastEntry.element : undefined;
216-
217-
const value = metric.value;
218-
219-
const end = getAbsoluteTime(value);
220-
221-
const data: ReplayPerformanceEntry<FirstInputDelayData> = {
222-
type: 'web-vital',
223-
name: 'first-input-delay',
224-
start: end,
225-
end,
226-
data: {
227-
value,
228-
size: value,
229-
nodeId: element ? record.mirror.getId(element) : undefined,
230-
},
231-
};
232-
233-
return data;
172+
}): ReplayPerformanceEntry<WebVitalData> {
173+
return getWebVital(metric, 'first-input-delay');
234174
}
235175

236176
/**
237177
* Add an INP event to the replay based on an INP metric.
238178
*/
239179
export function getInteractionToNextPaint(metric: {
240180
value: number;
181+
rating: 'good' | 'needs-improvement' | 'poor';
182+
entries: PerformanceEntry[];
183+
}): ReplayPerformanceEntry<WebVitalData> {
184+
return getWebVital(metric, 'interaction-to-next-paint');
185+
}
186+
187+
/**
188+
* Add an web vital event to the replay based on the web vital metric.
189+
*/
190+
export function getWebVital(metric: {
191+
value: number;
192+
rating: 'good' | 'needs-improvement' | 'poor';
241193
entries: PerformanceEntry[];
242-
}): ReplayPerformanceEntry<InteractionToNextPaintData> {
194+
}, name: string): ReplayPerformanceEntry<WebVitalData> {
243195
const entries = metric.entries;
244196
const lastEntry = entries[entries.length - 1] as (PerformanceEntry & { element?: Element }) | undefined;
245197
const element = lastEntry ? lastEntry.element : undefined;
246198

247199
const value = metric.value;
200+
const rating = metric.rating;
248201

249202
const end = getAbsoluteTime(value);
250203

251-
const data: ReplayPerformanceEntry<InteractionToNextPaintData> = {
204+
const data: ReplayPerformanceEntry<WebVitalData> = {
252205
type: 'web-vital',
253-
name: 'interaction-to-next-paint',
206+
name,
254207
start: end,
255208
end,
256209
data: {
257210
value,
258211
size: value,
212+
rating,
259213
nodeId: element ? record.mirror.getId(element) : undefined,
260214
},
261215
};

0 commit comments

Comments
 (0)