@@ -321,7 +321,7 @@ describe('Tests the SDK functionality', () => {
321
321
expect ( result ) . toBeNull ( ) ;
322
322
} ) ;
323
323
324
- it ( 'should filters out dsn breadcrumbs' , ( ) => {
324
+ it ( 'should filter out dsn breadcrumbs' , ( ) => {
325
325
( getDevServer as jest . Mock ) . mockReturnValue ( { url : 'http://localhost:8081' } ) ;
326
326
327
327
const mockBeforeBreadcrumb = ( breadcrumb : Breadcrumb , _hint ?: BreadcrumbHint ) => {
@@ -345,37 +345,76 @@ describe('Tests the SDK functionality', () => {
345
345
expect ( result ) . toBeNull ( ) ;
346
346
} ) ;
347
347
348
- it ( 'should keep breadcrumbs matching dsn if the url parsing fails for dsn ' , ( ) => {
348
+ it ( 'should filter out dsn breadcrumbs that the ports match ' , ( ) => {
349
349
( getDevServer as jest . Mock ) . mockReturnValue ( { url : 'http://localhost:8081' } ) ;
350
350
351
351
const mockBeforeBreadcrumb = ( breadcrumb : Breadcrumb , _hint ?: BreadcrumbHint ) => {
352
352
return breadcrumb ;
353
353
} ;
354
354
355
- // Mock the URL constructor to throw an exception for this test case
356
- const originalURL = ( global as any ) . URL ;
357
- jest . spyOn ( global as any , 'URL' ) . mockImplementationOnce ( ( ) => {
358
- throw new Error ( 'Failed to parse DSN URL' ) ;
359
- } ) ;
355
+ const passedOptions = {
356
+ dsn :
'https://[email protected] :8181/1234567' ,
357
+ beforeBreadcrumb : mockBeforeBreadcrumb ,
358
+ } ;
359
+
360
+ init ( passedOptions ) ;
361
+
362
+ const breadcrumb : Breadcrumb = {
363
+ type : 'http' ,
364
+ data : { url : 'https://selfhosted.app.server:8181/api' } ,
365
+ } ;
366
+
367
+ const result = usedOptions ( ) ?. beforeBreadcrumb ! ( breadcrumb ) ;
368
+
369
+ expect ( result ) . toBeNull ( ) ;
370
+ } ) ;
371
+
372
+ it ( 'should keep breadcrumbs if the ports do not match' , ( ) => {
373
+ ( getDevServer as jest . Mock ) . mockReturnValue ( { url : 'http://localhost:8081' } ) ;
374
+
375
+ const mockBeforeBreadcrumb = ( breadcrumb : Breadcrumb , _hint ?: BreadcrumbHint ) => {
376
+ return breadcrumb ;
377
+ } ;
360
378
361
379
const passedOptions = {
362
- dsn :
'https://[email protected] /1234567' ,
380
+ dsn :
'https://[email protected] :8181 /1234567' ,
363
381
beforeBreadcrumb : mockBeforeBreadcrumb ,
364
382
} ;
365
383
366
384
init ( passedOptions ) ;
367
385
368
386
const breadcrumb : Breadcrumb = {
369
387
type : 'http' ,
370
- data : { url : 'https://def.ingest.sentry.io/1234567 ' } ,
388
+ data : { url : 'https://selfhosted.app.server:8080/api ' } ,
371
389
} ;
372
390
373
391
const result = usedOptions ( ) ?. beforeBreadcrumb ! ( breadcrumb ) ;
374
392
375
393
expect ( result ) . toEqual ( breadcrumb ) ;
394
+ } ) ;
395
+
396
+ it ( 'should keep breadcrumbs if the url parsing fails for dsn' , ( ) => {
397
+ ( getDevServer as jest . Mock ) . mockReturnValue ( { url : 'http://localhost:8081' } ) ;
398
+
399
+ const mockBeforeBreadcrumb = ( breadcrumb : Breadcrumb , _hint ?: BreadcrumbHint ) => {
400
+ return breadcrumb ;
401
+ } ;
402
+
403
+ const passedOptions = {
404
+ dsn : 'invalid-dsn' ,
405
+ beforeBreadcrumb : mockBeforeBreadcrumb ,
406
+ } ;
407
+
408
+ init ( passedOptions ) ;
376
409
377
- // Restore the original URL constructor
378
- ( global as any ) . URL = originalURL ;
410
+ const breadcrumb : Breadcrumb = {
411
+ type : 'http' ,
412
+ data : { url : 'https://def.ingest.sentry.io/1234567' } ,
413
+ } ;
414
+
415
+ const result = usedOptions ( ) ?. beforeBreadcrumb ! ( breadcrumb ) ;
416
+
417
+ expect ( result ) . toEqual ( breadcrumb ) ;
379
418
} ) ;
380
419
381
420
it ( 'should keep non dev server or dsn breadcrumbs' , ( ) => {
0 commit comments