@@ -4,7 +4,7 @@ import { sentryTest } from '../../../../utils/fixtures';
44import { envelopeUrlRegex , shouldSkipTracingTest } from '../../../../utils/helpers' ;
55
66sentryTest (
7- 'there should be no span created for fetch requests with no active span' ,
7+ 'should not create span for fetch requests with no active span but should attach sentry-trace header ' ,
88 async ( { getLocalTestPath, page } ) => {
99 if ( shouldSkipTracingTest ( ) ) {
1010 sentryTest . skip ( ) ;
@@ -13,23 +13,32 @@ sentryTest(
1313 const url = await getLocalTestPath ( { testDir : __dirname } ) ;
1414
1515 let requestCount = 0 ;
16+ const sentryTraceHeaders : string [ ] = [ ] ;
1617 page . on ( 'request' , request => {
17- expect ( envelopeUrlRegex . test ( request . url ( ) ) ) . toBe ( false ) ;
18+ const url = request . url ( ) ;
19+
20+ const sentryTraceHeader = request . headers ( ) [ 'sentry-trace' ] ;
21+ if ( sentryTraceHeader ) {
22+ sentryTraceHeaders . push ( sentryTraceHeader ) ;
23+ }
24+ expect ( envelopeUrlRegex . test ( url ) ) . toBe ( false ) ;
25+
26+ // We only want to count API requests
27+ if ( url . endsWith ( '.html' ) || url . endsWith ( '.js' ) || url . endsWith ( '.css' ) || url . endsWith ( '.map' ) ) {
28+ return ;
29+ }
1830 requestCount ++ ;
1931 } ) ;
2032
2133 await page . goto ( url ) ;
2234
23- // Here are the requests that should exist:
24- // 1. HTML page
25- // 2. Init JS bundle
26- // 3. Subject JS bundle
27- // 4 [OPTIONAl] CDN JS bundle
28- // and then 3 fetch requests
29- if ( process . env . PW_BUNDLE && process . env . PW_BUNDLE . startsWith ( 'bundle_' ) ) {
30- expect ( requestCount ) . toBe ( 7 ) ;
31- } else {
32- expect ( requestCount ) . toBe ( 6 ) ;
33- }
35+ expect ( requestCount ) . toBe ( 3 ) ;
36+
37+ expect ( sentryTraceHeaders ) . toHaveLength ( 3 ) ;
38+ expect ( sentryTraceHeaders ) . toEqual ( [
39+ expect . stringMatching ( / ^ ( [ a - f 0 - 9 ] { 32 } ) - ( [ a - f 0 - 9 ] { 16 } ) $ / ) ,
40+ expect . stringMatching ( / ^ ( [ a - f 0 - 9 ] { 32 } ) - ( [ a - f 0 - 9 ] { 16 } ) $ / ) ,
41+ expect . stringMatching ( / ^ ( [ a - f 0 - 9 ] { 32 } ) - ( [ a - f 0 - 9 ] { 16 } ) $ / ) ,
42+ ] ) ;
3443 } ,
3544) ;
0 commit comments