1
- import { Event , Integration } from '@sentry/types' ;
1
+ /* eslint-disable @typescript-eslint/unbound-method */
2
+ import { Event , Hub , Integration } from '@sentry/types' ;
2
3
3
4
import { CaptureConsole } from '../src/captureconsole' ;
4
5
@@ -16,10 +17,11 @@ const mockHub = {
16
17
captureException : jest . fn ( ) ,
17
18
} ;
18
19
19
- const getMockHubWithIntegration = ( integration : Integration ) => ( {
20
- ...mockHub ,
21
- getIntegration : jest . fn ( ( ) => integration ) ,
22
- } ) ;
20
+ const getMockHubWithIntegration = ( integration : Integration ) =>
21
+ ( {
22
+ ...mockHub ,
23
+ getIntegration : jest . fn ( ( ) => integration ) ,
24
+ } as unknown as Hub ) ;
23
25
24
26
// We're using this to un-monkey patch the console after each test.
25
27
const originalConsole = Object . assign ( { } , global . console ) ;
@@ -36,7 +38,7 @@ describe('CaptureConsole setup', () => {
36
38
const captureConsoleIntegration = new CaptureConsole ( { levels : [ 'log' , 'warn' ] } ) ;
37
39
captureConsoleIntegration . setupOnce (
38
40
( ) => undefined ,
39
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
41
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
40
42
) ;
41
43
42
44
expect ( global . console . error ) . toBe ( originalConsole . error ) ; // not monkey patched
@@ -48,7 +50,7 @@ describe('CaptureConsole setup', () => {
48
50
const captureConsoleIntegration = new CaptureConsole ( ) ;
49
51
captureConsoleIntegration . setupOnce (
50
52
( ) => undefined ,
51
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
53
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
52
54
) ;
53
55
54
56
// expect a set of defined console levels to have been monkey patched
@@ -68,7 +70,7 @@ describe('CaptureConsole setup', () => {
68
70
const captureConsoleIntegration = new CaptureConsole ( { levels : [ ] } ) ;
69
71
captureConsoleIntegration . setupOnce (
70
72
( ) => undefined ,
71
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
73
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
72
74
) ;
73
75
74
76
// expect the default set of console levels not to have been monkey patched
@@ -93,7 +95,7 @@ describe('CaptureConsole setup', () => {
93
95
const captureConsoleIntegration = new CaptureConsole ( ) ;
94
96
captureConsoleIntegration . setupOnce (
95
97
( ) => undefined ,
96
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
98
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
97
99
) ;
98
100
} ) . not . toThrow ( ) ;
99
101
@@ -105,7 +107,7 @@ describe('CaptureConsole setup', () => {
105
107
const captureConsoleIntegration = new CaptureConsole ( { levels : [ 'error' ] } ) ;
106
108
captureConsoleIntegration . setupOnce (
107
109
( ) => undefined ,
108
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
110
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
109
111
) ;
110
112
111
113
// call a wrapped function
@@ -119,7 +121,7 @@ describe('CaptureConsole setup', () => {
119
121
const captureConsoleIntegration = new CaptureConsole ( { levels : [ 'log' ] } ) ;
120
122
captureConsoleIntegration . setupOnce (
121
123
( ) => undefined ,
122
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
124
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
123
125
) ;
124
126
125
127
// call a wrapped function
@@ -135,7 +137,7 @@ describe('CaptureConsole setup', () => {
135
137
const captureConsoleIntegration = new CaptureConsole ( { levels : [ 'log' ] } ) ;
136
138
captureConsoleIntegration . setupOnce (
137
139
( ) => undefined ,
138
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
140
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
139
141
) ;
140
142
141
143
// call a wrapped function
@@ -154,7 +156,7 @@ describe('CaptureConsole setup', () => {
154
156
const captureConsoleIntegration = new CaptureConsole ( { levels : [ 'assert' ] } ) ;
155
157
captureConsoleIntegration . setupOnce (
156
158
( ) => undefined ,
157
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
159
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
158
160
) ;
159
161
160
162
global . console . assert ( 1 + 1 === 3 ) ;
@@ -168,7 +170,7 @@ describe('CaptureConsole setup', () => {
168
170
const captureConsoleIntegration = new CaptureConsole ( { levels : [ 'assert' ] } ) ;
169
171
captureConsoleIntegration . setupOnce (
170
172
( ) => undefined ,
171
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
173
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
172
174
) ;
173
175
174
176
global . console . assert ( 1 + 1 === 3 , 'expression is false' ) ;
@@ -182,7 +184,7 @@ describe('CaptureConsole setup', () => {
182
184
const captureConsoleIntegration = new CaptureConsole ( { levels : [ 'assert' ] } ) ;
183
185
captureConsoleIntegration . setupOnce (
184
186
( ) => undefined ,
185
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
187
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
186
188
) ;
187
189
188
190
global . console . assert ( 1 + 1 === 2 ) ;
@@ -192,7 +194,7 @@ describe('CaptureConsole setup', () => {
192
194
const captureConsoleIntegration = new CaptureConsole ( { levels : [ 'error' ] } ) ;
193
195
captureConsoleIntegration . setupOnce (
194
196
( ) => undefined ,
195
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
197
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
196
198
) ;
197
199
198
200
const someError = new Error ( 'some error' ) ;
@@ -206,7 +208,7 @@ describe('CaptureConsole setup', () => {
206
208
const captureConsoleIntegration = new CaptureConsole ( ) ;
207
209
captureConsoleIntegration . setupOnce (
208
210
( ) => undefined ,
209
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
211
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
210
212
) ;
211
213
212
214
const someError = new Error ( 'some error' ) ;
@@ -220,7 +222,7 @@ describe('CaptureConsole setup', () => {
220
222
const captureConsoleIntegration = new CaptureConsole ( ) ;
221
223
captureConsoleIntegration . setupOnce (
222
224
( ) => undefined ,
223
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
225
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
224
226
) ;
225
227
226
228
global . console . error ( 'some message' ) ;
@@ -233,7 +235,7 @@ describe('CaptureConsole setup', () => {
233
235
const captureConsoleIntegration = new CaptureConsole ( { levels : [ 'error' ] } ) ;
234
236
captureConsoleIntegration . setupOnce (
235
237
( ) => undefined ,
236
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
238
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
237
239
) ;
238
240
239
241
global . console . error ( 'some non-error message' ) ;
@@ -247,7 +249,7 @@ describe('CaptureConsole setup', () => {
247
249
const captureConsoleIntegration = new CaptureConsole ( { levels : [ 'info' ] } ) ;
248
250
captureConsoleIntegration . setupOnce (
249
251
( ) => undefined ,
250
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
252
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
251
253
) ;
252
254
253
255
global . console . info ( 'some message' ) ;
@@ -265,7 +267,7 @@ describe('CaptureConsole setup', () => {
265
267
const captureConsoleIntegration = new CaptureConsole ( { levels : [ 'log' ] } ) ;
266
268
captureConsoleIntegration . setupOnce (
267
269
( ) => undefined ,
268
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
270
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
269
271
) ;
270
272
271
273
global . console . log ( 'some message 1' , 'some message 2' ) ;
@@ -281,11 +283,11 @@ describe('CaptureConsole setup', () => {
281
283
const captureConsoleIntegration = new CaptureConsole ( { levels : [ 'log' , 'someNonExistingLevel' , 'error' ] } ) ;
282
284
captureConsoleIntegration . setupOnce (
283
285
( ) => undefined ,
284
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
286
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
285
287
) ;
286
288
287
289
// The provided level should not be created
288
- expect ( global . console [ 'someNonExistingLevel' ] ) . toBeUndefined ( ) ;
290
+ expect ( ( global . console as any ) [ 'someNonExistingLevel' ] ) . toBeUndefined ( ) ;
289
291
290
292
// Ohter levels should be wrapped as expected
291
293
expect ( global . console . log ) . not . toBe ( originalConsole . log ) ;
@@ -296,7 +298,7 @@ describe('CaptureConsole setup', () => {
296
298
const captureConsoleIntegration = new CaptureConsole ( { levels : [ 'log' , 'error' ] } ) ;
297
299
captureConsoleIntegration . setupOnce (
298
300
( ) => undefined ,
299
- ( ) => getMockHubWithIntegration ( null ) as any , // simulate not having the integration registered
301
+ ( ) => getMockHubWithIntegration ( null as any ) , // simulate not having the integration registered
300
302
) ;
301
303
302
304
// Console should be wrapped
@@ -310,12 +312,12 @@ describe('CaptureConsole setup', () => {
310
312
311
313
it ( "should not crash when the original console methods don't exist at time of invocation" , ( ) => {
312
314
const originalConsoleLog = global . console . log ;
313
- global . console . log = undefined ; // don't `delete` here, otherwise `fill` won't wrap the function
315
+ global . console . log = undefined as any ; // don't `delete` here, otherwise `fill` won't wrap the function
314
316
315
317
const captureConsoleIntegration = new CaptureConsole ( { levels : [ 'log' ] } ) ;
316
318
captureConsoleIntegration . setupOnce (
317
319
( ) => undefined ,
318
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
320
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
319
321
) ;
320
322
321
323
expect ( ( ) => {
0 commit comments