@@ -7,6 +7,7 @@ import type {
7
7
Event ,
8
8
EventEnvelope ,
9
9
EventEnvelopeHeaders ,
10
+ SessionContext ,
10
11
TransactionEvent ,
11
12
} from '@sentry/core' ;
12
13
@@ -157,7 +158,7 @@ export const countEnvelopes = async (
157
158
* @param {{ path?: string; content?: string } } impl
158
159
* @return {* } {Promise<void>}
159
160
*/
160
- async function runScriptInSandbox (
161
+ export async function runScriptInSandbox (
161
162
page : Page ,
162
163
impl : {
163
164
path ?: string ;
@@ -178,7 +179,7 @@ async function runScriptInSandbox(
178
179
* @param {string } [url]
179
180
* @return {* } {Promise<Array<Event>>}
180
181
*/
181
- async function getSentryEvents ( page : Page , url ?: string ) : Promise < Array < Event > > {
182
+ export async function getSentryEvents ( page : Page , url ?: string ) : Promise < Array < Event > > {
182
183
if ( url ) {
183
184
await page . goto ( url ) ;
184
185
}
@@ -250,6 +251,25 @@ export function waitForTransactionRequest(
250
251
} ) ;
251
252
}
252
253
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
+
253
273
/**
254
274
* We can only test tracing tests in certain bundles/packages:
255
275
* - NPM (ESM, CJS)
@@ -353,7 +373,7 @@ async function getMultipleRequests<T>(
353
373
/**
354
374
* Wait and get multiple envelope requests at the given URL, or the current page
355
375
*/
356
- async function getMultipleSentryEnvelopeRequests < T > (
376
+ export async function getMultipleSentryEnvelopeRequests < T > (
357
377
page : Page ,
358
378
count : number ,
359
379
options ?: {
@@ -374,7 +394,7 @@ async function getMultipleSentryEnvelopeRequests<T>(
374
394
* @param {string } [url]
375
395
* @return {* } {Promise<T>}
376
396
*/
377
- async function getFirstSentryEnvelopeRequest < T > (
397
+ export async function getFirstSentryEnvelopeRequest < T > (
378
398
page : Page ,
379
399
url ?: string ,
380
400
requestParser : ( req : Request ) => T = envelopeRequestParser as ( req : Request ) => T ,
@@ -388,5 +408,3 @@ async function getFirstSentryEnvelopeRequest<T>(
388
408
389
409
return req ;
390
410
}
391
-
392
- export { runScriptInSandbox , getMultipleSentryEnvelopeRequests , getFirstSentryEnvelopeRequest , getSentryEvents } ;
0 commit comments