Skip to content

Commit 90a326e

Browse files
Fix: Wait for session before navigating to avoid race condition
Co-authored-by: aprasad <aprasad@sentry.io>
1 parent 5c51fdb commit 90a326e

File tree

1 file changed

+5
-2
lines changed
  • dev-packages/browser-integration-tests/suites/sessions/initial-scope

1 file changed

+5
-2
lines changed

dev-packages/browser-integration-tests/suites/sessions/initial-scope/test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Route } from '@playwright/test';
22
import { expect } from '@playwright/test';
33
import type { SessionContext } from '@sentry/core';
44
import { sentryTest } from '../../../utils/fixtures';
5-
import { getFirstSentryEnvelopeRequest } from '../../../utils/helpers';
5+
import { getFirstSentryEnvelopeRequest, waitForSession } from '../../../utils/helpers';
66

77
sentryTest('should start a new session on pageload.', async ({ getLocalTestUrl, page }) => {
88
const url = await getLocalTestUrl({ testDir: __dirname });
@@ -22,9 +22,12 @@ sentryTest('should start a new session with navigation.', async ({ getLocalTestU
2222

2323
const initSession = await getFirstSentryEnvelopeRequest<SessionContext>(page, url);
2424

25+
// Set up session listener BEFORE clicking to avoid race condition
26+
// between the click-triggered navigation and a second page.goto() call
27+
const newSessionPromise = waitForSession(page);
2528
await page.click('#navigate');
2629

27-
const newSession = await getFirstSentryEnvelopeRequest<SessionContext>(page, url);
30+
const newSession = await newSessionPromise;
2831

2932
expect(newSession).toBeDefined();
3033
expect(newSession.init).toBe(true);

0 commit comments

Comments
 (0)