Skip to content

Commit 4bc8457

Browse files
committed
make test less flaky
1 parent 7cd982a commit 4bc8457

File tree

1 file changed

+14
-12
lines changed
  • dev-packages/browser-integration-tests/suites/feedback/captureFeedbackAndReplay/hasSampling

1 file changed

+14
-12
lines changed

dev-packages/browser-integration-tests/suites/feedback/captureFeedbackAndReplay/hasSampling/test.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { expect } from '@playwright/test';
33
import { sentryTest } from '../../../../utils/fixtures';
44
import { envelopeRequestParser, getEnvelopeType, shouldSkipFeedbackTest } from '../../../../utils/helpers';
55
import {
6-
getCustomRecordingEvents,
7-
getReplayEvent,
6+
collectReplayRequests,
7+
getReplayBreadcrumbs,
88
shouldSkipReplayTest,
99
waitForReplayRequest,
1010
} from '../../../../utils/replayHelpers';
@@ -15,8 +15,7 @@ sentryTest('should capture feedback', async ({ forceFlushReplay, getLocalTestPat
1515
}
1616

1717
const reqPromise0 = waitForReplayRequest(page, 0);
18-
const reqPromise1 = waitForReplayRequest(page, 1);
19-
const reqPromise2 = waitForReplayRequest(page, 2);
18+
2019
const feedbackRequestPromise = page.waitForResponse(res => {
2120
const req = res.request();
2221

@@ -42,27 +41,30 @@ sentryTest('should capture feedback', async ({ forceFlushReplay, getLocalTestPat
4241

4342
const url = await getLocalTestPath({ testDir: __dirname });
4443

45-
const [, , replayReq0] = await Promise.all([page.goto(url), page.getByText('Report a Bug').click(), reqPromise0]);
44+
await Promise.all([page.goto(url), page.getByText('Report a Bug').click(), reqPromise0]);
45+
46+
const replayRequestPromise = collectReplayRequests(page, recordingEvents => {
47+
return getReplayBreadcrumbs(recordingEvents).some(breadcrumb => breadcrumb.category === 'sentry.feedback');
48+
});
4649

4750
// Inputs are slow, these need to be serial
4851
await page.locator('[name="name"]').fill('Jane Doe');
4952
await page.locator('[name="email"]').fill('[email protected]');
5053
await page.locator('[name="message"]').fill('my example feedback');
5154

5255
// Force flush here, as inputs are slow and can cause click event to be in unpredictable segments
53-
await Promise.all([forceFlushReplay(), reqPromise1]);
56+
await Promise.all([forceFlushReplay()]);
5457

55-
const [, feedbackResp, replayReq2] = await Promise.all([
58+
const [, feedbackResp] = await Promise.all([
5659
page.locator('[data-sentry-feedback] .btn--primary').click(),
5760
feedbackRequestPromise,
58-
reqPromise2,
5961
]);
6062

63+
const { replayEvents, replayRecordingSnapshots } = await replayRequestPromise;
64+
const breadcrumbs = getReplayBreadcrumbs(replayRecordingSnapshots);
65+
66+
const replayEvent = replayEvents[0];
6167
const feedbackEvent = envelopeRequestParser(feedbackResp.request());
62-
const replayEvent = getReplayEvent(replayReq0);
63-
// Feedback breadcrumb is on second segment because we flush when "Report a Bug" is clicked
64-
// And then the breadcrumb is sent when feedback form is submitted
65-
const { breadcrumbs } = getCustomRecordingEvents(replayReq2);
6668

6769
expect(breadcrumbs).toEqual(
6870
expect.arrayContaining([

0 commit comments

Comments
 (0)