@@ -24,6 +24,7 @@ import { DEFAULT_NAVIGATION_SPAN_NAME } from '../../src/js/tracing/span';
24
24
import { RN_GLOBAL_OBJ } from '../../src/js/utils/worldwide' ;
25
25
import { getDefaultTestClientOptions , TestClient } from '../mocks/client' ;
26
26
import { NATIVE } from '../mockWrapper' ;
27
+ import { getDevServer } from './../../src/js/integrations/debugsymbolicatorutils' ;
27
28
import { createMockNavigationAndAttachTo } from './reactnavigationutils' ;
28
29
29
30
const dummyRoute = {
@@ -32,6 +33,9 @@ const dummyRoute = {
32
33
} ;
33
34
34
35
jest . mock ( '../../src/js/wrapper.ts' , ( ) => jest . requireActual ( '../mockWrapper.ts' ) ) ;
36
+ jest . mock ( './../../src/js/integrations/debugsymbolicatorutils' , ( ) => ( {
37
+ getDevServer : jest . fn ( ) ,
38
+ } ) ) ;
35
39
jest . useFakeTimers ( { advanceTimers : true } ) ;
36
40
37
41
class MockNavigationContainer {
@@ -392,6 +396,67 @@ describe('ReactNavigationInstrumentation', () => {
392
396
} ) ;
393
397
} ) ;
394
398
399
+ describe ( 'shouldCreateSpanForRequest' , ( ) => {
400
+ it ( 'should return false for Dev Server URLs' , ( ) => {
401
+ const devServerUrl = 'http://localhost:8081' ;
402
+ ( getDevServer as jest . Mock ) . mockReturnValue ( { url : devServerUrl } ) ;
403
+
404
+ const rnTracing = reactNativeTracingIntegration ( ) ;
405
+
406
+ const result = rnTracing . options . shouldCreateSpanForRequest ( devServerUrl ) ;
407
+
408
+ expect ( result ) . toBe ( false ) ;
409
+ } ) ;
410
+
411
+ it ( 'should return true for non Dev Server URLs' , ( ) => {
412
+ const devServerUrl = 'http://localhost:8081' ;
413
+ ( getDevServer as jest . Mock ) . mockReturnValue ( { url : devServerUrl } ) ;
414
+
415
+ const rnTracing = reactNativeTracingIntegration ( ) ;
416
+
417
+ const result = rnTracing . options . shouldCreateSpanForRequest ( 'http://some-other-url.com' ) ;
418
+
419
+ expect ( result ) . toBe ( true ) ;
420
+ } ) ;
421
+
422
+ it ( 'should chain the user defined shouldCreateSpanForRequest if defined' , ( ) => {
423
+ const devServerUrl = 'http://localhost:8081' ;
424
+ ( getDevServer as jest . Mock ) . mockReturnValue ( { url : devServerUrl } ) ;
425
+
426
+ const userShouldCreateSpanForRequest = ( _url : string ) : boolean => {
427
+ return false ;
428
+ } ;
429
+
430
+ const rnTracing = reactNativeTracingIntegration ( { shouldCreateSpanForRequest : userShouldCreateSpanForRequest } ) ;
431
+
432
+ const result = rnTracing . options . shouldCreateSpanForRequest ( 'http://some-other-url.com' ) ;
433
+
434
+ expect ( result ) . toBe ( false ) ;
435
+ } ) ;
436
+
437
+ it ( 'should handle undefined devServerUrls by using only the user defined shouldCreateSpanForRequest' , ( ) => {
438
+ ( getDevServer as jest . Mock ) . mockReturnValue ( { url : undefined } ) ;
439
+
440
+ const userShouldCreateSpanForRequest = ( _url : string ) : boolean => {
441
+ return true ;
442
+ } ;
443
+
444
+ const rnTracing = reactNativeTracingIntegration ( { shouldCreateSpanForRequest : userShouldCreateSpanForRequest } ) ;
445
+
446
+ const result = rnTracing . options . shouldCreateSpanForRequest ( 'http://any-url.com' ) ;
447
+
448
+ expect ( result ) . toBe ( true ) ;
449
+ } ) ;
450
+
451
+ it ( 'should not set the shouldCreateSpanForRequest if not user provided and the devServerUrl is undefined' , ( ) => {
452
+ ( getDevServer as jest . Mock ) . mockReturnValue ( { url : undefined } ) ;
453
+
454
+ const rnTracing = reactNativeTracingIntegration ( ) ;
455
+
456
+ expect ( rnTracing . options . shouldCreateSpanForRequest ) . toBe ( undefined ) ;
457
+ } ) ;
458
+ } ) ;
459
+
395
460
function setupTestClient (
396
461
setupOptions : {
397
462
beforeSpanStart ?: ( options : StartSpanOptions ) => StartSpanOptions ;
0 commit comments