Skip to content

Commit 6f1f01c

Browse files
committed
normalize snashot strings and fix LCP span
1 parent 03281b4 commit 6f1f01c

File tree

11 files changed

+29
-22
lines changed

11 files changed

+29
-22
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import {
1616
import {
1717
getReplayEvent,
1818
getReplayRecordingContent,
19+
normalize,
1920
shouldSkipReplayTest,
20-
stringify,
2121
waitForReplayRequest,
2222
} from '../../../utils/replayHelpers';
2323

@@ -53,7 +53,7 @@ sentryTest(
5353
const recording0 = getReplayRecordingContent(await reqPromise0);
5454

5555
expect(replayEvent0).toEqual(getExpectedReplayEvent({ segment_id: 0 }));
56-
expect(stringify(recording0.fullSnapshots)).toMatchSnapshot('seg-0-snap-full');
56+
expect(normalize(recording0.fullSnapshots)).toMatchSnapshot('seg-0-snap-full');
5757
expect(recording0.incrementalSnapshots.length).toEqual(0);
5858

5959
await page.click('#go-background');
@@ -65,7 +65,7 @@ sentryTest(
6565
getExpectedReplayEvent({ segment_id: 1, urls: [], replay_start_timestamp: undefined }),
6666
);
6767
expect(recording1.fullSnapshots.length).toEqual(0);
68-
expect(stringify(recording1.incrementalSnapshots)).toMatchSnapshot('seg-1-snap-incremental');
68+
expect(normalize(recording1.incrementalSnapshots)).toMatchSnapshot('seg-1-snap-incremental');
6969

7070
// We can't guarantee the order of the performance spans, or in which of the two segments they are sent
7171
// So to avoid flakes, we collect them all and check that they are all there
@@ -98,7 +98,7 @@ sentryTest(
9898
const recording2 = getReplayRecordingContent(await reqPromise2);
9999

100100
expect(replayEvent2).toEqual(getExpectedReplayEvent({ segment_id: 2, replay_start_timestamp: undefined }));
101-
expect(stringify(recording2.fullSnapshots)).toMatchSnapshot('seg-2-snap-full');
101+
expect(normalize(recording2.fullSnapshots)).toMatchSnapshot('seg-2-snap-full');
102102
expect(recording2.incrementalSnapshots.length).toEqual(0);
103103

104104
await page.click('#go-background');
@@ -110,7 +110,7 @@ sentryTest(
110110
getExpectedReplayEvent({ segment_id: 3, urls: [], replay_start_timestamp: undefined }),
111111
);
112112
expect(recording3.fullSnapshots.length).toEqual(0);
113-
expect(stringify(recording3.incrementalSnapshots)).toMatchSnapshot('seg-3-snap-incremental');
113+
expect(normalize(recording3.incrementalSnapshots)).toMatchSnapshot('seg-3-snap-incremental');
114114

115115
const collectedPerformanceSpansAfterReload = [...recording2.performanceSpans, ...recording3.performanceSpans];
116116
const collectedBreadcrumbsAdterReload = [...recording2.breadcrumbs, ...recording3.breadcrumbs];
@@ -156,7 +156,7 @@ sentryTest(
156156
},
157157
}),
158158
);
159-
expect(stringify(recording4.fullSnapshots)).toMatchSnapshot('seg-4-snap-full');
159+
expect(normalize(recording4.fullSnapshots)).toMatchSnapshot('seg-4-snap-full');
160160
expect(recording4.incrementalSnapshots.length).toEqual(0);
161161

162162
await page.click('#go-background');
@@ -180,7 +180,7 @@ sentryTest(
180180
}),
181181
);
182182
expect(recording5.fullSnapshots.length).toEqual(0);
183-
expect(stringify(recording5.incrementalSnapshots)).toMatchSnapshot('seg-5-snap-incremental');
183+
expect(normalize(recording5.incrementalSnapshots)).toMatchSnapshot('seg-5-snap-incremental');
184184

185185
const collectedPerformanceSpansAfterLinkNavigation = [
186186
...recording4.performanceSpans,
@@ -227,7 +227,7 @@ sentryTest(
227227
}),
228228
);
229229
expect(recording6.fullSnapshots.length).toEqual(0);
230-
expect(stringify(recording6.incrementalSnapshots)).toMatchSnapshot('seg-6-snap-incremental');
230+
expect(normalize(recording6.incrementalSnapshots)).toMatchSnapshot('seg-6-snap-incremental');
231231

232232
await page.click('#go-background');
233233

@@ -251,7 +251,7 @@ sentryTest(
251251
}),
252252
);
253253
expect(recording7.fullSnapshots.length).toEqual(0);
254-
expect(stringify(recording7.incrementalSnapshots)).toMatchSnapshot('seg-7-snap-incremental');
254+
expect(normalize(recording7.incrementalSnapshots)).toMatchSnapshot('seg-7-snap-incremental');
255255

256256
const collectedPerformanceSpansAfterSPANavigation = [
257257
...recording6.performanceSpans,
@@ -291,7 +291,7 @@ sentryTest(
291291
replay_start_timestamp: undefined,
292292
}),
293293
);
294-
expect(stringify(recording8.fullSnapshots)).toMatchSnapshot('seg-8-snap-full');
294+
expect(normalize(recording8.fullSnapshots)).toMatchSnapshot('seg-8-snap-full');
295295
expect(recording8.incrementalSnapshots.length).toEqual(0);
296296

297297
await page.click('#go-background');
@@ -307,7 +307,7 @@ sentryTest(
307307
}),
308308
);
309309
expect(recording9.fullSnapshots.length).toEqual(0);
310-
expect(stringify(recording9.incrementalSnapshots)).toMatchSnapshot('seg-9-snap-incremental');
310+
expect(normalize(recording9.incrementalSnapshots)).toMatchSnapshot('seg-9-snap-incremental');
311311

312312
const collectedPerformanceSpansAfterIndexNavigation = [
313313
...recording8.performanceSpans,

packages/integration-tests/suites/replay/multiple-pages/test.ts-snapshots/seg-0-snap-full

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"type": 2,
7272
"tagName": "a",
7373
"attributes": {
74-
"href": "file:///Users/lukas/code/sentry-javascript/packages/integration-tests/suites/replay/multiple-pages/dist/page-0.html"
74+
"href": "/page-0.html"
7575
},
7676
"childNodes": [
7777
{

packages/integration-tests/suites/replay/multiple-pages/test.ts-snapshots/seg-0-snap-full-chromium

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"type": 2,
7272
"tagName": "a",
7373
"attributes": {
74-
"href": "file:///Users/lukas/code/sentry-javascript/packages/integration-tests/suites/replay/multiple-pages/dist/page-0.html"
74+
"href": "/page-0.html"
7575
},
7676
"childNodes": [
7777
{

packages/integration-tests/suites/replay/multiple-pages/test.ts-snapshots/seg-2-snap-full

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"type": 2,
7272
"tagName": "a",
7373
"attributes": {
74-
"href": "file:///Users/lukas/code/sentry-javascript/packages/integration-tests/suites/replay/multiple-pages/dist/page-0.html"
74+
"href": "/page-0.html"
7575
},
7676
"childNodes": [
7777
{

packages/integration-tests/suites/replay/multiple-pages/test.ts-snapshots/seg-2-snap-full-chromium

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"type": 2,
7272
"tagName": "a",
7373
"attributes": {
74-
"href": "file:///Users/lukas/code/sentry-javascript/packages/integration-tests/suites/replay/multiple-pages/dist/page-0.html"
74+
"href": "/page-0.html"
7575
},
7676
"childNodes": [
7777
{

packages/integration-tests/suites/replay/multiple-pages/test.ts-snapshots/seg-4-snap-full

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
"type": 2,
115115
"tagName": "a",
116116
"attributes": {
117-
"href": "file:///Users/lukas/code/sentry-javascript/packages/integration-tests/suites/replay/multiple-pages/dist/index.html"
117+
"href": "/index.html"
118118
},
119119
"childNodes": [
120120
{

packages/integration-tests/suites/replay/multiple-pages/test.ts-snapshots/seg-4-snap-full-chromium

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
"type": 2,
115115
"tagName": "a",
116116
"attributes": {
117-
"href": "file:///Users/lukas/code/sentry-javascript/packages/integration-tests/suites/replay/multiple-pages/dist/index.html"
117+
"href": "/index.html"
118118
},
119119
"childNodes": [
120120
{

packages/integration-tests/suites/replay/multiple-pages/test.ts-snapshots/seg-8-snap-full

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"type": 2,
7272
"tagName": "a",
7373
"attributes": {
74-
"href": "file:///Users/lukas/code/sentry-javascript/packages/integration-tests/suites/replay/multiple-pages/dist/page-0.html"
74+
"href": "/page-0.html"
7575
},
7676
"childNodes": [
7777
{

packages/integration-tests/suites/replay/multiple-pages/test.ts-snapshots/seg-8-snap-full-chromium

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"type": 2,
7272
"tagName": "a",
7373
"attributes": {
74-
"href": "file:///Users/lukas/code/sentry-javascript/packages/integration-tests/suites/replay/multiple-pages/dist/page-0.html"
74+
"href": "/page-0.html"
7575
},
7676
"childNodes": [
7777
{

packages/integration-tests/utils/replayEventTemplates.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export const expectedLCPPerformanceSpan = {
110110
startTimestamp: expect.any(Number),
111111
endTimestamp: expect.any(Number),
112112
data: {
113-
value: expect.any(Number),
113+
duration: expect.any(Number),
114114
nodeId: expect.any(Number),
115115
size: expect.any(Number),
116116
},

packages/integration-tests/utils/replayHelpers.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,13 @@ export function shouldSkipReplayTest(): boolean {
210210
return bundle != null && !bundle.includes('replay') && !bundle.includes('esm') && !bundle.includes('cjs');
211211
}
212212

213-
export function stringify(obj: unknown): string {
214-
return JSON.stringify(obj, null, 2);
213+
/**
214+
* Takes a replay recording payload and returns a normalized string representation.
215+
* This is necessary because the DOM snapshots contain absolute paths to other HTML
216+
* files which break the tests on different machines.
217+
*/
218+
export function normalize(obj: unknown): string {
219+
const rawString = JSON.stringify(obj, null, 2);
220+
const normalizedString = rawString.replace(/"file:\/\/.+(\/.*\.html)"/g, '"$1"');
221+
return normalizedString;
215222
}

0 commit comments

Comments
 (0)