Skip to content

Commit 6380c4e

Browse files
committed
fix stuff actually
1 parent 5b717ae commit 6380c4e

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

dev-packages/browser-integration-tests/suites/sessions/update-session/test.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import { expect } from '@playwright/test';
22
import type { SessionContext } from '@sentry/core';
33

44
import { sentryTest } from '../../../utils/fixtures';
5-
import { getFirstSentryEnvelopeRequest } from '../../../utils/helpers';
5+
import { getFirstSentryEnvelopeRequest, waitForSession } from '../../../utils/helpers';
66

77
sentryTest('should update session when an error is thrown.', async ({ getLocalTestUrl, page }) => {
88
const url = await getLocalTestUrl({ testDir: __dirname });
9+
910
const pageloadSession = await getFirstSentryEnvelopeRequest<SessionContext>(page, url);
10-
const updatedSession = (
11-
await Promise.all([page.locator('#throw-error').click(), getFirstSentryEnvelopeRequest<SessionContext>(page)])
12-
)[1];
11+
12+
const updatedSessionPromise = waitForSession(page);
13+
await page.locator('#throw-error').click();
14+
const updatedSession = await updatedSessionPromise;
1315

1416
expect(pageloadSession).toBeDefined();
1517
expect(pageloadSession.init).toBe(true);
@@ -25,9 +27,10 @@ sentryTest('should update session when an exception is captured.', async ({ getL
2527
const url = await getLocalTestUrl({ testDir: __dirname });
2628

2729
const pageloadSession = await getFirstSentryEnvelopeRequest<SessionContext>(page, url);
28-
const updatedSession = (
29-
await Promise.all([page.locator('#capture-exception').click(), getFirstSentryEnvelopeRequest<SessionContext>(page)])
30-
)[1];
30+
31+
const updatedSessionPromise = waitForSession(page);
32+
await page.locator('#capture-exception').click();
33+
const updatedSession = await updatedSessionPromise;
3134

3235
expect(pageloadSession).toBeDefined();
3336
expect(pageloadSession.init).toBe(true);

dev-packages/browser-integration-tests/utils/helpers.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
Event,
88
EventEnvelope,
99
EventEnvelopeHeaders,
10+
SessionContext,
1011
TransactionEvent,
1112
} from '@sentry/core';
1213

@@ -157,7 +158,7 @@ export const countEnvelopes = async (
157158
* @param {{ path?: string; content?: string }} impl
158159
* @return {*} {Promise<void>}
159160
*/
160-
async function runScriptInSandbox(
161+
export async function runScriptInSandbox(
161162
page: Page,
162163
impl: {
163164
path?: string;
@@ -178,7 +179,7 @@ async function runScriptInSandbox(
178179
* @param {string} [url]
179180
* @return {*} {Promise<Array<Event>>}
180181
*/
181-
async function getSentryEvents(page: Page, url?: string): Promise<Array<Event>> {
182+
export async function getSentryEvents(page: Page, url?: string): Promise<Array<Event>> {
182183
if (url) {
183184
await page.goto(url);
184185
}
@@ -250,6 +251,25 @@ export function waitForTransactionRequest(
250251
});
251252
}
252253

254+
export async function waitForSession(page: Page): Promise<SessionContext> {
255+
const req = await page.waitForRequest(req => {
256+
const postData = req.postData();
257+
if (!postData) {
258+
return false;
259+
}
260+
261+
try {
262+
const event = envelopeRequestParser<SessionContext>(req);
263+
264+
return typeof event.init === 'boolean' && event.started !== undefined;
265+
} catch {
266+
return false;
267+
}
268+
});
269+
270+
return envelopeRequestParser<SessionContext>(req);
271+
}
272+
253273
/**
254274
* We can only test tracing tests in certain bundles/packages:
255275
* - NPM (ESM, CJS)
@@ -353,7 +373,7 @@ async function getMultipleRequests<T>(
353373
/**
354374
* Wait and get multiple envelope requests at the given URL, or the current page
355375
*/
356-
async function getMultipleSentryEnvelopeRequests<T>(
376+
export async function getMultipleSentryEnvelopeRequests<T>(
357377
page: Page,
358378
count: number,
359379
options?: {
@@ -374,7 +394,7 @@ async function getMultipleSentryEnvelopeRequests<T>(
374394
* @param {string} [url]
375395
* @return {*} {Promise<T>}
376396
*/
377-
async function getFirstSentryEnvelopeRequest<T>(
397+
export async function getFirstSentryEnvelopeRequest<T>(
378398
page: Page,
379399
url?: string,
380400
requestParser: (req: Request) => T = envelopeRequestParser as (req: Request) => T,
@@ -388,5 +408,3 @@ async function getFirstSentryEnvelopeRequest<T>(
388408

389409
return req;
390410
}
391-
392-
export { runScriptInSandbox, getMultipleSentryEnvelopeRequests, getFirstSentryEnvelopeRequest, getSentryEvents };

packages/core/src/baseclient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
822822
}
823823

824824
const session = currentScope.getSession() || isolationScope.getSession();
825-
if (!isError && session) {
825+
if (isError && session) {
826826
this._updateSessionFromEvent(session, processedEvent);
827827
}
828828

0 commit comments

Comments
 (0)