@@ -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 } ;
0 commit comments