@@ -321,7 +321,7 @@ describe('Tests the SDK functionality', () => {
321321 expect ( result ) . toBeNull ( ) ;
322322 } ) ;
323323
324- it ( 'should filters out dsn breadcrumbs' , ( ) => {
324+ it ( 'should filter out dsn breadcrumbs' , ( ) => {
325325 ( getDevServer as jest . Mock ) . mockReturnValue ( { url : 'http://localhost:8081' } ) ;
326326
327327 const mockBeforeBreadcrumb = ( breadcrumb : Breadcrumb , _hint ?: BreadcrumbHint ) => {
@@ -345,37 +345,76 @@ describe('Tests the SDK functionality', () => {
345345 expect ( result ) . toBeNull ( ) ;
346346 } ) ;
347347
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 ' , ( ) => {
349349 ( getDevServer as jest . Mock ) . mockReturnValue ( { url : 'http://localhost:8081' } ) ;
350350
351351 const mockBeforeBreadcrumb = ( breadcrumb : Breadcrumb , _hint ?: BreadcrumbHint ) => {
352352 return breadcrumb ;
353353 } ;
354354
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://sentry@selfhosted.app.server: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+ } ;
360378
361379 const passedOptions = {
362- dsn : 'https://abc@def.ingest.sentry.io /1234567' ,
380+ dsn : 'https://sentry@selfhosted.app.server:8181 /1234567' ,
363381 beforeBreadcrumb : mockBeforeBreadcrumb ,
364382 } ;
365383
366384 init ( passedOptions ) ;
367385
368386 const breadcrumb : Breadcrumb = {
369387 type : 'http' ,
370- data : { url : 'https://def.ingest.sentry.io/1234567 ' } ,
388+ data : { url : 'https://selfhosted.app.server:8080/api ' } ,
371389 } ;
372390
373391 const result = usedOptions ( ) ?. beforeBreadcrumb ! ( breadcrumb ) ;
374392
375393 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 ) ;
376409
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 ) ;
379418 } ) ;
380419
381420 it ( 'should keep non dev server or dsn breadcrumbs' , ( ) => {
0 commit comments