Skip to content

Commit 4389c5e

Browse files
committed
try fix flaky test??
1 parent 2921c5e commit 4389c5e

File tree

1 file changed

+14
-2
lines changed
  • packages/browser-integration-tests/suites/replay/slowClick/multiClick

1 file changed

+14
-2
lines changed

packages/browser-integration-tests/suites/replay/slowClick/multiClick/test.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ sentryTest('captures multi click when not detecting slow click', async ({ getLoc
5959
]);
6060
});
6161

62-
sentryTest('captures multiple multi clicks', async ({ getLocalTestUrl, page }) => {
62+
sentryTest('captures multiple multi clicks', async ({ getLocalTestUrl, page, forceFlushReplay }) => {
6363
if (shouldSkipReplayTest()) {
6464
sentryTest.skip();
6565
}
@@ -104,13 +104,18 @@ sentryTest('captures multiple multi clicks', async ({ getLocalTestUrl, page }) =
104104
return check;
105105
});
106106

107+
const time = Date.now();
108+
107109
await page.click('#mutationButtonImmediately', { clickCount: 4 });
108110

109-
await new Promise(resolve => setTimeout(resolve, 1001));
111+
// Ensure we waited at least 1s, which is the threshold to create a new ui.click breadcrumb
112+
await waitForFunction(() => Date.now() - time > 1000);
110113

111114
await page.click('#mutationButtonImmediately', { clickCount: 2 });
112115

113116
const { breadcrumbs } = getCustomRecordingEvents(await reqPromise1);
117+
await forceFlushReplay();
118+
114119
const { breadcrumbs: breadcrumb2 } = getCustomRecordingEvents(await reqPromise2);
115120

116121
const slowClickBreadcrumbs = breadcrumbs
@@ -160,3 +165,10 @@ sentryTest('captures multiple multi clicks', async ({ getLocalTestUrl, page }) =
160165
},
161166
]);
162167
});
168+
169+
async function waitForFunction(cb: () => boolean, timeout = 2000, increment = 100) {
170+
while (timeout > 0 && !cb()) {
171+
await new Promise(resolve => setTimeout(resolve, increment));
172+
await waitForFunction(cb, timeout - increment, increment);
173+
}
174+
}

0 commit comments

Comments
 (0)