@@ -4,7 +4,7 @@ import { sentryTest } from '../../../../utils/fixtures';
4
4
import { envelopeUrlRegex , shouldSkipTracingTest } from '../../../../utils/helpers' ;
5
5
6
6
sentryTest (
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 ' ,
8
8
async ( { getLocalTestPath, page } ) => {
9
9
if ( shouldSkipTracingTest ( ) ) {
10
10
sentryTest . skip ( ) ;
@@ -13,23 +13,32 @@ sentryTest(
13
13
const url = await getLocalTestPath ( { testDir : __dirname } ) ;
14
14
15
15
let requestCount = 0 ;
16
+ const sentryTraceHeaders : string [ ] = [ ] ;
16
17
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
+ }
18
30
requestCount ++ ;
19
31
} ) ;
20
32
21
33
await page . goto ( url ) ;
22
34
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
+ ] ) ;
34
43
} ,
35
44
) ;
0 commit comments