@@ -2,10 +2,13 @@ import type { Event as SentryEvent, ExtendedError } from '@sentry/types';
2
2
3
3
import { extraErrorDataIntegration } from '../../../src/integrations/extraerrordata' ;
4
4
5
+ import { TestClient , getDefaultTestClientOptions } from '../../mocks/client' ;
6
+
5
7
const extraErrorData = extraErrorDataIntegration ( ) ;
6
8
let event : SentryEvent ;
7
9
8
10
describe ( 'ExtraErrorData()' , ( ) => {
11
+ const testClient = new TestClient ( getDefaultTestClientOptions ( { maxValueLength : 250 } ) ) ;
9
12
beforeEach ( ( ) => {
10
13
event = { } ;
11
14
} ) ;
@@ -20,7 +23,7 @@ describe('ExtraErrorData()', () => {
20
23
{
21
24
originalException : error ,
22
25
} ,
23
- { } as any ,
26
+ testClient ,
24
27
) as SentryEvent ;
25
28
26
29
expect ( enhancedEvent . contexts ) . toEqual ( {
@@ -31,6 +34,27 @@ describe('ExtraErrorData()', () => {
31
34
} ) ;
32
35
} ) ;
33
36
37
+ it ( 'should use maxValueLength to truncate extra data' , ( ) => {
38
+ const error = new TypeError ( 'foo' ) as ExtendedError ;
39
+ error . baz = 42 ;
40
+ error . foo = 'a' . repeat ( 300 ) ;
41
+
42
+ const enhancedEvent = extraErrorData . processEvent ?.(
43
+ event ,
44
+ {
45
+ originalException : error ,
46
+ } ,
47
+ testClient ,
48
+ ) as SentryEvent ;
49
+
50
+ expect ( enhancedEvent . contexts ) . toEqual ( {
51
+ TypeError : {
52
+ baz : 42 ,
53
+ foo : `${ 'a' . repeat ( 250 ) } ...` ,
54
+ } ,
55
+ } ) ;
56
+ } ) ;
57
+
34
58
it ( 'doesnt choke on linked errors and stringify names instead' , ( ) => {
35
59
const error = new TypeError ( 'foo' ) as ExtendedError ;
36
60
error . cause = new SyntaxError ( 'bar' ) ;
@@ -40,7 +64,7 @@ describe('ExtraErrorData()', () => {
40
64
{
41
65
originalException : error ,
42
66
} ,
43
- { } as any ,
67
+ testClient ,
44
68
) as SentryEvent ;
45
69
46
70
expect ( enhancedEvent . contexts ) . toEqual ( {
@@ -65,7 +89,7 @@ describe('ExtraErrorData()', () => {
65
89
{
66
90
originalException : error ,
67
91
} ,
68
- { } as any ,
92
+ testClient ,
69
93
) as SentryEvent ;
70
94
71
95
expect ( enhancedEvent . contexts ) . toEqual ( {
@@ -93,7 +117,7 @@ describe('ExtraErrorData()', () => {
93
117
{
94
118
originalException : error ,
95
119
} ,
96
- { } as any ,
120
+ testClient ,
97
121
) as SentryEvent ;
98
122
99
123
expect ( enhancedEvent . contexts ) . toEqual ( {
@@ -112,14 +136,14 @@ describe('ExtraErrorData()', () => {
112
136
{
113
137
originalException : error ,
114
138
} ,
115
- { } as any ,
139
+ testClient ,
116
140
) as SentryEvent ;
117
141
118
142
expect ( enhancedEvent ) . toEqual ( event ) ;
119
143
} ) ;
120
144
121
145
it ( 'should return event if there is no SentryEventHint' , ( ) => {
122
- const enhancedEvent = extraErrorData . processEvent ?.( event , { } , { } as any ) ;
146
+ const enhancedEvent = extraErrorData . processEvent ?.( event , { } , testClient ) ;
123
147
124
148
expect ( enhancedEvent ) . toEqual ( event ) ;
125
149
} ) ;
@@ -131,7 +155,7 @@ describe('ExtraErrorData()', () => {
131
155
// @ts -expect-error Allow event to have extra properties
132
156
notOriginalException : 'fooled you' ,
133
157
} ,
134
- { } as any ,
158
+ testClient ,
135
159
) ;
136
160
137
161
expect ( enhancedEvent ) . toEqual ( event ) ;
@@ -153,7 +177,7 @@ describe('ExtraErrorData()', () => {
153
177
{
154
178
originalException : error ,
155
179
} ,
156
- { } as any ,
180
+ testClient ,
157
181
) as SentryEvent ;
158
182
159
183
expect ( enhancedEvent . contexts ) . toEqual ( {
@@ -180,7 +204,7 @@ describe('ExtraErrorData()', () => {
180
204
{
181
205
originalException : error ,
182
206
} ,
183
- { } as any ,
207
+ testClient ,
184
208
) as SentryEvent ;
185
209
186
210
expect ( enhancedEvent . contexts ) . toEqual ( {
@@ -204,7 +228,7 @@ describe('ExtraErrorData()', () => {
204
228
{
205
229
originalException : error ,
206
230
} ,
207
- { } as any ,
231
+ testClient ,
208
232
) as SentryEvent ;
209
233
210
234
expect ( enhancedEvent . contexts ) . toEqual ( {
@@ -232,7 +256,7 @@ describe('ExtraErrorData()', () => {
232
256
{
233
257
originalException : error ,
234
258
} ,
235
- { } as any ,
259
+ testClient ,
236
260
) as SentryEvent ;
237
261
238
262
expect ( enhancedEvent . contexts ) . toEqual ( {
@@ -261,7 +285,7 @@ describe('ExtraErrorData()', () => {
261
285
{
262
286
originalException : error ,
263
287
} ,
264
- { } as any ,
288
+ testClient ,
265
289
) as SentryEvent ;
266
290
267
291
expect ( enhancedEvent . contexts ) . not . toEqual ( {
0 commit comments