@@ -30,8 +30,11 @@ sentryTest('it does not download the SDK if the SDK was loaded in the meanwhile'
3030 const tmpDir = await getLocalTestUrl ( { testDir : __dirname , skipRouteHandler : true , skipDsnRouteHandler : true } ) ;
3131
3232 await page . route ( `${ TEST_HOST } /*.*` , route => {
33- const file = route . request ( ) . url ( ) . split ( '/' ) . pop ( ) ;
33+ const pathname = new URL ( route . request ( ) . url ( ) ) . pathname ;
34+ const file = pathname . split ( '/' ) . pop ( ) || '' ;
3435
36+ // Loader + subject both fetch the CDN bundle. Chromium may not hit `page.route` twice for the same URL
37+ // (memory cache); subject.js uses a cache-busted URL so we reliably observe two network loads.
3538 if ( file === 'cdn.bundle.js' ) {
3639 cdnLoadedCount ++ ;
3740 }
@@ -47,10 +50,8 @@ sentryTest('it does not download the SDK if the SDK was loaded in the meanwhile'
4750
4851 const eventData = envelopeRequestParser ( req ) ;
4952
50- await waitForFunction ( ( ) => cdnLoadedCount === 2 ) ;
51-
5253 // Still loaded the CDN bundle twice
53- expect ( cdnLoadedCount ) . toBe ( 2 ) ;
54+ await expect . poll ( ( ) => cdnLoadedCount , { timeout : 15_000 } ) . toBe ( 2 ) ;
5455
5556 // But only sent to Sentry once
5657 expect ( sentryEventCount ) . toBe ( 1 ) ;
@@ -62,10 +63,3 @@ sentryTest('it does not download the SDK if the SDK was loaded in the meanwhile'
6263 expect ( eventData . exception ?. values ?. length ) . toBe ( 1 ) ;
6364 expect ( eventData . exception ?. values ?. [ 0 ] ?. value ) . toBe ( 'window.doSomethingWrong is not a function' ) ;
6465} ) ;
65-
66- async function waitForFunction ( cb : ( ) => boolean , timeout = 2000 , increment = 100 ) {
67- while ( timeout > 0 && ! cb ( ) ) {
68- await new Promise ( resolve => setTimeout ( resolve , increment ) ) ;
69- await waitForFunction ( cb , timeout - increment , increment ) ;
70- }
71- }
0 commit comments