Skip to content

Commit 636f4d9

Browse files
authored
test(browser-integration): Tweak promises a bit to reduce flakes in replay tests (#9477)
...maybe Based on what we did in #9025
1 parent 0485d11 commit 636f4d9

File tree

3 files changed

+19
-20
lines changed
  • packages/browser-integration-tests/suites
    • integrations/Breadcrumbs/dom/click
    • replay
      • extendNetworkBreadcrumbs/xhr/captureRequestHeaders
      • privacyInputMaskAll

3 files changed

+19
-20
lines changed

packages/browser-integration-tests/suites/integrations/Breadcrumbs/dom/click/test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ sentryTest('captures Breadcrumb for clicks & debounces them for a second', async
3333
await page.waitForTimeout(1000);
3434
await page.click('#button2');
3535

36-
await page.evaluate('Sentry.captureException("test exception")');
37-
38-
const eventData = await promise;
36+
const [eventData] = await Promise.all([promise, page.evaluate('Sentry.captureException("test exception")')]);
3937

4038
expect(eventData.exception?.values).toHaveLength(1);
4139

packages/browser-integration-tests/suites/replay/extendNetworkBreadcrumbs/xhr/captureRequestHeaders/test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ sentryTest('captures request headers', async ({ getLocalTestPath, page, browserN
5454
/* eslint-enable */
5555
});
5656

57-
const request = await requestPromise;
57+
const [request, replayReq1] = await Promise.all([requestPromise, replayRequestPromise1]);
5858
const eventData = envelopeRequestParser(request);
5959

6060
expect(eventData.exception?.values).toHaveLength(1);
@@ -71,7 +71,6 @@ sentryTest('captures request headers', async ({ getLocalTestPath, page, browserN
7171
},
7272
});
7373

74-
const replayReq1 = await replayRequestPromise1;
7574
const { performanceSpans: performanceSpans1 } = getCustomRecordingEvents(replayReq1);
7675
expect(performanceSpans1.filter(span => span.op === 'resource.xhr')).toEqual([
7776
{
@@ -142,7 +141,8 @@ sentryTest(
142141
/* eslint-enable */
143142
});
144143

145-
const request = await requestPromise;
144+
const [request, replayReq1] = await Promise.all([requestPromise, replayRequestPromise1]);
145+
146146
const eventData = envelopeRequestParser(request);
147147

148148
expect(eventData.exception?.values).toHaveLength(1);
@@ -159,7 +159,6 @@ sentryTest(
159159
},
160160
});
161161

162-
const replayReq1 = await replayRequestPromise1;
163162
const { performanceSpans: performanceSpans1 } = getCustomRecordingEvents(replayReq1);
164163
expect(performanceSpans1.filter(span => span.op === 'resource.xhr')).toEqual([
165164
{

packages/browser-integration-tests/suites/replay/privacyInputMaskAll/test.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,24 @@ sentryTest(
5757
const url = await getLocalTestPath({ testDir: __dirname });
5858

5959
await page.goto(url);
60-
const fullSnapshot = getFullRecordingSnapshots(await reqPromise0);
60+
61+
const text = 'test';
62+
63+
const [req0] = await Promise.all([reqPromise0, page.locator('#input').fill(text)]);
64+
await forceFlushReplay();
65+
66+
const fullSnapshot = getFullRecordingSnapshots(req0);
6167
const stringifiedSnapshot = JSON.stringify(fullSnapshot);
6268
expect(stringifiedSnapshot.includes('Submit form')).toBe(false);
6369
expect(stringifiedSnapshot.includes('Unmasked button')).toBe(true);
6470

65-
const text = 'test';
66-
67-
await page.locator('#input').fill(text);
71+
const [req1] = await Promise.all([reqPromise1, page.locator('#input-unmasked').fill(text)]);
6872
await forceFlushReplay();
6973

70-
const snapshots = getIncrementalRecordingSnapshots(await reqPromise1).filter(isInputMutation);
74+
const snapshots = getIncrementalRecordingSnapshots(req1).filter(isInputMutation);
7175
const lastSnapshot = snapshots[snapshots.length - 1];
7276
expect(lastSnapshot.data.text).toBe('*'.repeat(text.length));
7377

74-
await page.locator('#input-unmasked').fill(text);
75-
await forceFlushReplay();
7678
const snapshots2 = getIncrementalRecordingSnapshots(await reqPromise2).filter(isInputMutation);
7779
const lastSnapshot2 = snapshots2[snapshots2.length - 1];
7880
expect(lastSnapshot2.data.text).toBe(text);
@@ -120,18 +122,18 @@ sentryTest(
120122

121123
await page.goto(url);
122124

123-
await reqPromise0;
124-
125125
const text = 'test';
126126

127-
await page.locator('#textarea').fill(text);
127+
await Promise.all([reqPromise0, page.locator('#textarea').fill(text)]);
128+
await forceFlushReplay();
129+
130+
const [req1] = await Promise.all([reqPromise1, page.locator('#textarea-unmasked').fill(text)]);
128131
await forceFlushReplay();
129-
const snapshots = getIncrementalRecordingSnapshots(await reqPromise1).filter(isInputMutation);
132+
133+
const snapshots = getIncrementalRecordingSnapshots(req1).filter(isInputMutation);
130134
const lastSnapshot = snapshots[snapshots.length - 1];
131135
expect(lastSnapshot.data.text).toBe('*'.repeat(text.length));
132136

133-
await page.locator('#textarea-unmasked').fill(text);
134-
await forceFlushReplay();
135137
const snapshots2 = getIncrementalRecordingSnapshots(await reqPromise2).filter(isInputMutation);
136138
const lastSnapshot2 = snapshots2[snapshots2.length - 1];
137139
expect(lastSnapshot2.data.text).toBe(text);

0 commit comments

Comments
 (0)