11import  {  ERROR_TRACKING_SUPPRESSION_RULES  }  from  '../constants' 
2- import  {  PostHog  }  from  '../posthog-core' 
2+ import  {  defaultConfig ,   PostHog  }  from  '../posthog-core' 
33import  {  PostHogExceptions  }  from  '../posthog-exceptions' 
44import  {  PostHogPersistence  }  from  '../posthog-persistence' 
55import  { 
6-     FlagsResponse , 
76    ErrorTrackingSuppressionRule , 
87    ErrorTrackingSuppressionRuleValue , 
98    PostHogConfig , 
109    Property , 
10+     RemoteConfig , 
1111}  from  '../types' 
1212
1313function  createSuppressionRule ( 
@@ -37,7 +37,7 @@ describe('PostHogExceptions', () => {
3737    let  config : PostHogConfig 
3838
3939    beforeEach ( ( )  =>  { 
40-         config  =  {  persistence : 'memory'  }   as   unknown   as   PostHogConfig 
40+         config  =  {  ... defaultConfig ( ) ,   persistence : 'memory'  } 
4141
4242        const  postHogPersistence  =  new  PostHogPersistence ( config ) 
4343        postHogPersistence . clear ( ) 
@@ -67,8 +67,8 @@ describe('PostHogExceptions', () => {
6767    describe ( 'onRemoteConfig' ,  ( )  =>  { 
6868        it ( 'persists the suppression rules' ,  ( )  =>  { 
6969            const  suppressionRule  =  createSuppressionRule ( ) 
70-             const  flagsResponse : Partial < FlagsResponse >  =  {  errorTracking : {  suppressionRules : [ suppressionRule ]  }  } 
71-             exceptions . onRemoteConfig ( flagsResponse  as  FlagsResponse ) 
70+             const  remoteResponse : Partial < RemoteConfig >  =  {  errorTracking : {  suppressionRules : [ suppressionRule ]  }  } 
71+             exceptions . onRemoteConfig ( remoteResponse  as  RemoteConfig ) 
7272            expect ( exceptions [ '_suppressionRules' ] ) . toEqual ( [ suppressionRule ] ) 
7373        } ) 
7474    } ) 
@@ -84,21 +84,21 @@ describe('PostHogExceptions', () => {
8484            [ 'GenericError' ,  'This is a message that contains a ReactMinified error' ] , 
8585        ] ) ( 'drops the event if a suppression rule matches' ,  ( type ,  value )  =>  { 
8686            const  suppressionRule  =  createSuppressionRule ( 'OR' ) 
87-             exceptions . onRemoteConfig ( {  errorTracking : {  suppressionRules : [ suppressionRule ]  }  }  as  FlagsResponse ) 
87+             exceptions . onRemoteConfig ( {  errorTracking : {  suppressionRules : [ suppressionRule ]  }  }  as  RemoteConfig ) 
8888            exceptions . sendExceptionEvent ( {  $exception_list : [ {  type,  value } ]  } ) 
8989            expect ( captureMock ) . not . toBeCalled ( ) 
9090        } ) 
9191
9292        it ( 'captures an exception if no $exception_list property exists' ,  ( )  =>  { 
9393            const  suppressionRule  =  createSuppressionRule ( 'AND' ) 
94-             exceptions . onRemoteConfig ( {  errorTracking : {  suppressionRules : [ suppressionRule ]  }  }  as  FlagsResponse ) 
94+             exceptions . onRemoteConfig ( {  errorTracking : {  suppressionRules : [ suppressionRule ]  }  }  as  RemoteConfig ) 
9595            exceptions . sendExceptionEvent ( {  custom_property : true  } ) 
9696            expect ( captureMock ) . toBeCalled ( ) 
9797        } ) 
9898
9999        it ( 'captures an exception if all rule conditions do not match' ,  ( )  =>  { 
100100            const  suppressionRule  =  createSuppressionRule ( 'AND' ) 
101-             exceptions . onRemoteConfig ( {  errorTracking : {  suppressionRules : [ suppressionRule ]  }  }  as  FlagsResponse ) 
101+             exceptions . onRemoteConfig ( {  errorTracking : {  suppressionRules : [ suppressionRule ]  }  }  as  RemoteConfig ) 
102102            exceptions . sendExceptionEvent ( {  $exception_list : [ {  type : 'TypeError' ,  value : 'This is a type error'  } ]  } ) 
103103            expect ( captureMock ) . toBeCalled ( ) 
104104        } ) 
@@ -112,9 +112,24 @@ describe('PostHogExceptions', () => {
112112                    type : 'error_tracking_issue_property' , 
113113                } , 
114114            ] ) 
115-             exceptions . onRemoteConfig ( {  errorTracking : {  suppressionRules : [ suppressionRule ]  }  }  as  FlagsResponse ) 
115+             exceptions . onRemoteConfig ( {  errorTracking : {  suppressionRules : [ suppressionRule ]  }  }  as  RemoteConfig ) 
116116            exceptions . sendExceptionEvent ( {  $exception_list : [ {  type : 'TypeError' ,  value : 'This is a type error'  } ]  } ) 
117117            expect ( captureMock ) . toBeCalled ( ) 
118118        } ) 
119+ 
120+         it ( 'does not capture exceptions with frames from extensions by default' ,  ( )  =>  { 
121+             const  frame  =  {  filename : 'chrome-extension://' ,  platform : 'javascript:web'  } 
122+             const  exception  =  {  stacktrace : {  frames : [ frame ] ,  type : 'raw'  }  } 
123+             exceptions . sendExceptionEvent ( {  $exception_list : [ exception ]  } ) 
124+             expect ( captureMock ) . not . toBeCalledWith ( '$exception' ,  {  $exception_list : [ exception ]  } ,  expect . anything ( ) ) 
125+         } ) 
126+ 
127+         it ( 'captures extension exceptions when enabled' ,  ( )  =>  { 
128+             exceptions . onRemoteConfig ( {  errorTracking : {  captureExtensionExceptions : true  }  }  as  RemoteConfig ) 
129+             const  frame  =  {  filename : 'chrome-extension://' ,  platform : 'javascript:web'  } 
130+             const  exception  =  {  stacktrace : {  frames : [ frame ] ,  type : 'raw'  }  } 
131+             exceptions . sendExceptionEvent ( {  $exception_list : [ exception ]  } ) 
132+             expect ( captureMock ) . toBeCalledWith ( '$exception' ,  {  $exception_list : [ exception ]  } ,  expect . anything ( ) ) 
133+         } ) 
119134    } ) 
120135} ) 
0 commit comments