11import { ExtendedError } from '@sentry/types' ;
2- import { stub } from 'sinon' ;
32
43import { BrowserBackend } from '../../../src/backend' ;
5- import { LinkedErrors } from '../../../src/integrations/linkederrors' ;
6-
7- let linkedErrors : any ;
4+ import * as LinkedErrorsModule from '../../../src/integrations/linkederrors' ;
85
96describe ( 'LinkedErrors' , ( ) => {
10- beforeEach ( ( ) => {
11- linkedErrors = new LinkedErrors ( ) ;
12- } ) ;
13-
147 describe ( 'handler' , ( ) => {
15- it ( 'should bail out if event doesnt contain exception' , ( ) => {
16- const spy = stub ( linkedErrors , '_walkErrorTree' ) ;
8+ it ( 'should bail out if event does not contain exception' , ( ) => {
179 const event = {
1810 message : 'foo' ,
1911 } ;
20- const result = linkedErrors . _handler ( event ) ;
21- expect ( spy . called ) . toBe ( false ) ;
12+ const result = LinkedErrorsModule . _handler ( 'cause' , 5 , event ) ;
2213 expect ( result ) . toEqual ( event ) ;
2314 } ) ;
2415
2516 it ( 'should bail out if event contains exception, but no hint' , ( ) => {
26- const spy = stub ( linkedErrors , '_walkErrorTree' ) ;
2717 const event = {
2818 exception : {
2919 values : [ ] ,
3020 } ,
3121 message : 'foo' ,
3222 } ;
33- const result = linkedErrors . _handler ( event ) ;
34- expect ( spy . called ) . toBe ( false ) ;
23+ const result = LinkedErrorsModule . _handler ( 'cause' , 5 , event ) ;
3524 expect ( result ) . toEqual ( event ) ;
3625 } ) ;
3726
38- it ( 'should call walkErrorTree if event contains exception and hint with originalException' , ( ) => {
39- const spy = stub ( linkedErrors , '_walkErrorTree' ) . callsFake ( ( ) => [ ] ) ;
40- const event = {
41- exception : {
42- values : [ ] ,
43- } ,
44- message : 'foo' ,
45- } ;
46- const hint = {
47- originalException : new Error ( 'originalException' ) ,
48- } ;
49- linkedErrors . _handler ( event , hint ) ;
50- expect ( spy . calledOnce ) . toBe ( true ) ;
51- } ) ;
52-
5327 it ( 'should recursively walk error to find linked exceptions and assign them to the event' , async ( ) => {
5428 const three : ExtendedError = new SyntaxError ( 'three' ) ;
5529
@@ -62,7 +36,7 @@ describe('LinkedErrors', () => {
6236 const originalException = one ;
6337 const backend = new BrowserBackend ( { } ) ;
6438 return backend . eventFromException ( originalException ) . then ( event => {
65- const result = linkedErrors . _handler ( event , {
39+ const result = LinkedErrorsModule . _handler ( 'cause' , 5 , event , {
6640 originalException,
6741 } ) ;
6842
@@ -81,10 +55,6 @@ describe('LinkedErrors', () => {
8155 } ) ;
8256
8357 it ( 'should allow to change walk key' , async ( ) => {
84- linkedErrors = new LinkedErrors ( {
85- key : 'reason' ,
86- } ) ;
87-
8858 const three : ExtendedError = new SyntaxError ( 'three' ) ;
8959
9060 const two : ExtendedError = new TypeError ( 'two' ) ;
@@ -96,7 +66,7 @@ describe('LinkedErrors', () => {
9666 const originalException = one ;
9767 const backend = new BrowserBackend ( { } ) ;
9868 return backend . eventFromException ( originalException ) . then ( event => {
99- const result = linkedErrors . _handler ( event , {
69+ const result = LinkedErrorsModule . _handler ( 'reason' , 5 , event , {
10070 originalException,
10171 } ) ;
10272
@@ -114,20 +84,17 @@ describe('LinkedErrors', () => {
11484 } ) ;
11585
11686 it ( 'should allow to change stack size limit' , async ( ) => {
117- linkedErrors = new LinkedErrors ( {
118- limit : 2 ,
119- } ) ;
120-
12187 const one : ExtendedError = new Error ( 'one' ) ;
12288 const two : ExtendedError = new TypeError ( 'two' ) ;
12389 const three : ExtendedError = new SyntaxError ( 'three' ) ;
12490 one . cause = two ;
12591 two . cause = three ;
12692
12793 const backend = new BrowserBackend ( { } ) ;
128- return backend . eventFromException ( one ) . then ( event => {
129- const result = linkedErrors . _handler ( event , {
130- originalException : one ,
94+ const originalException = one ;
95+ return backend . eventFromException ( originalException ) . then ( event => {
96+ const result = LinkedErrorsModule . _handler ( 'cause' , 2 , event , {
97+ originalException,
13198 } ) ;
13299
133100 expect ( result . exception . values . length ) . toBe ( 2 ) ;
0 commit comments