@@ -26,20 +26,26 @@ sentryTest('should add resource spans to pageload transaction', async ({ getLoca
26
26
const eventData = await getFirstSentryEnvelopeRequest < Event > ( page , url ) ;
27
27
const resourceSpans = eventData . spans ?. filter ( ( { op } ) => op ?. startsWith ( 'resource' ) ) ;
28
28
29
- // Webkit 16.0 (which is linked to Playwright 1.27.1) consistently creates 2 consectutive spans for `css`,
30
- // so we need to check for 3 or 4 spans.
31
- if ( browser . browserType ( ) . name ( ) === 'webkit' ) {
32
- expect ( resourceSpans ?. length ) . toBeGreaterThanOrEqual ( 5 ) ;
33
- } else {
34
- expect ( resourceSpans ?. length ) . toBe ( 5 ) ;
29
+ const scriptSpans = resourceSpans ?. filter ( ( { op } ) => op === 'resource.script' ) ;
30
+ const linkSpans = resourceSpans ?. filter ( ( { op } ) => op === 'resource.link' ) ;
31
+ const imgSpans = resourceSpans ?. filter ( ( { op } ) => op === 'resource.img' ) ;
32
+
33
+ expect ( imgSpans ) . toHaveLength ( 1 ) ;
34
+ expect ( linkSpans ) . toHaveLength ( 1 ) ;
35
+
36
+ const hasCdnBundle = ( process . env . PW_BUNDLE || '' ) . startsWith ( 'bundle' ) ;
37
+
38
+ const expectedScripts = [ '/init.bundle.js' , '/subject.bundle.js' , 'https://example.com/path/to/script.js' ] ;
39
+ if ( hasCdnBundle ) {
40
+ expectedScripts . unshift ( '/cdn.bundle.js' ) ;
35
41
}
36
42
37
- [ 'resource.img' , 'resource.script' , 'resource.link' ] . forEach ( op =>
38
- expect ( resourceSpans ) . toContainEqual (
39
- expect . objectContaining ( {
40
- op : op ,
41
- parent_span_id : eventData . contexts ?. trace ?. span_id ,
42
- } ) ,
43
- ) ,
44
- ) ;
43
+ expect ( scriptSpans ?. map ( ( { description } ) => description ) . sort ( ) ) . toEqual ( expectedScripts ) ;
44
+
45
+ const spanId = eventData . contexts ?. trace ?. span_id ;
46
+
47
+ expect ( spanId ) . toBeDefined ( ) ;
48
+ expect ( imgSpans ?. [ 0 ] . parent_span_id ) . toBe ( spanId ) ;
49
+ expect ( linkSpans ?. [ 0 ] . parent_span_id ) . toBe ( spanId ) ;
50
+ expect ( scriptSpans ?. map ( ( { parent_span_id } ) => parent_span_id ) ) . toEqual ( expectedScripts . map ( ( ) => spanId ) ) ;
45
51
} ) ;
0 commit comments