1
1
import { ExtendedError } from '@sentry/types' ;
2
- import { stub } from 'sinon' ;
3
2
4
3
import { BrowserBackend } from '../../../src/backend' ;
5
- import { LinkedErrors } from '../../../src/integrations/linkederrors' ;
6
-
7
- let linkedErrors : any ;
4
+ import * as LinkedErrorsModule from '../../../src/integrations/linkederrors' ;
8
5
9
6
describe ( 'LinkedErrors' , ( ) => {
10
- beforeEach ( ( ) => {
11
- linkedErrors = new LinkedErrors ( ) ;
12
- } ) ;
13
-
14
7
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' , ( ) => {
17
9
const event = {
18
10
message : 'foo' ,
19
11
} ;
20
- const result = linkedErrors . _handler ( event ) ;
21
- expect ( spy . called ) . toBe ( false ) ;
12
+ const result = LinkedErrorsModule . _handler ( 'cause' , 5 , event ) ;
22
13
expect ( result ) . toEqual ( event ) ;
23
14
} ) ;
24
15
25
16
it ( 'should bail out if event contains exception, but no hint' , ( ) => {
26
- const spy = stub ( linkedErrors , '_walkErrorTree' ) ;
27
17
const event = {
28
18
exception : {
29
19
values : [ ] ,
30
20
} ,
31
21
message : 'foo' ,
32
22
} ;
33
- const result = linkedErrors . _handler ( event ) ;
34
- expect ( spy . called ) . toBe ( false ) ;
23
+ const result = LinkedErrorsModule . _handler ( 'cause' , 5 , event ) ;
35
24
expect ( result ) . toEqual ( event ) ;
36
25
} ) ;
37
26
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
-
53
27
it ( 'should recursively walk error to find linked exceptions and assign them to the event' , async ( ) => {
54
28
const three : ExtendedError = new SyntaxError ( 'three' ) ;
55
29
@@ -62,7 +36,7 @@ describe('LinkedErrors', () => {
62
36
const originalException = one ;
63
37
const backend = new BrowserBackend ( { } ) ;
64
38
return backend . eventFromException ( originalException ) . then ( event => {
65
- const result = linkedErrors . _handler ( event , {
39
+ const result = LinkedErrorsModule . _handler ( 'cause' , 5 , event , {
66
40
originalException,
67
41
} ) ;
68
42
@@ -81,10 +55,6 @@ describe('LinkedErrors', () => {
81
55
} ) ;
82
56
83
57
it ( 'should allow to change walk key' , async ( ) => {
84
- linkedErrors = new LinkedErrors ( {
85
- key : 'reason' ,
86
- } ) ;
87
-
88
58
const three : ExtendedError = new SyntaxError ( 'three' ) ;
89
59
90
60
const two : ExtendedError = new TypeError ( 'two' ) ;
@@ -96,7 +66,7 @@ describe('LinkedErrors', () => {
96
66
const originalException = one ;
97
67
const backend = new BrowserBackend ( { } ) ;
98
68
return backend . eventFromException ( originalException ) . then ( event => {
99
- const result = linkedErrors . _handler ( event , {
69
+ const result = LinkedErrorsModule . _handler ( 'reason' , 5 , event , {
100
70
originalException,
101
71
} ) ;
102
72
@@ -114,20 +84,17 @@ describe('LinkedErrors', () => {
114
84
} ) ;
115
85
116
86
it ( 'should allow to change stack size limit' , async ( ) => {
117
- linkedErrors = new LinkedErrors ( {
118
- limit : 2 ,
119
- } ) ;
120
-
121
87
const one : ExtendedError = new Error ( 'one' ) ;
122
88
const two : ExtendedError = new TypeError ( 'two' ) ;
123
89
const three : ExtendedError = new SyntaxError ( 'three' ) ;
124
90
one . cause = two ;
125
91
two . cause = three ;
126
92
127
93
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,
131
98
} ) ;
132
99
133
100
expect ( result . exception . values . length ) . toBe ( 2 ) ;
0 commit comments