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
@@ -25,10 +26,11 @@ const mockConsole = {
25
26
info : jest . fn ( ) ,
26
27
} ;
27
28
28
- const getMockHubWithIntegration = ( integration : Integration ) => ( {
29
- ...mockHub ,
30
- getIntegration : jest . fn ( ( ) => integration ) ,
31
- } ) ;
29
+ const getMockHubWithIntegration = ( integration : Integration ) =>
30
+ ( {
31
+ ...mockHub ,
32
+ getIntegration : jest . fn ( ( ) => integration ) ,
33
+ } as unknown as Hub ) ;
32
34
33
35
// We're using this to un-monkey patch the console after each test.
34
36
const originalConsole = Object . assign ( { } , global . console ) ;
@@ -59,7 +61,7 @@ describe('CaptureConsole setup', () => {
59
61
const captureConsoleIntegration = new CaptureConsole ( { levels : [ 'log' , 'warn' ] } ) ;
60
62
captureConsoleIntegration . setupOnce (
61
63
( ) => undefined ,
62
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
64
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
63
65
) ;
64
66
65
67
expect ( global . console . error ) . toBe ( originalConsole . error ) ; // not monkey patched
@@ -71,7 +73,7 @@ describe('CaptureConsole setup', () => {
71
73
const captureConsoleIntegration = new CaptureConsole ( ) ;
72
74
captureConsoleIntegration . setupOnce (
73
75
( ) => undefined ,
74
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
76
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
75
77
) ;
76
78
77
79
// expect a set of defined console levels to have been monkey patched
@@ -91,7 +93,7 @@ describe('CaptureConsole setup', () => {
91
93
const captureConsoleIntegration = new CaptureConsole ( { levels : [ ] } ) ;
92
94
captureConsoleIntegration . setupOnce (
93
95
( ) => undefined ,
94
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
96
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
95
97
) ;
96
98
97
99
// expect the default set of console levels not to have been monkey patched
@@ -120,7 +122,7 @@ describe('CaptureConsole setup', () => {
120
122
const captureConsoleIntegration = new CaptureConsole ( ) ;
121
123
captureConsoleIntegration . setupOnce (
122
124
( ) => undefined ,
123
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
125
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
124
126
) ;
125
127
} ) . not . toThrow ( ) ;
126
128
@@ -132,7 +134,7 @@ describe('CaptureConsole setup', () => {
132
134
const captureConsoleIntegration = new CaptureConsole ( { levels : [ 'error' ] } ) ;
133
135
captureConsoleIntegration . setupOnce (
134
136
( ) => undefined ,
135
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
137
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
136
138
) ;
137
139
138
140
// call a wrapped function
@@ -146,7 +148,7 @@ describe('CaptureConsole setup', () => {
146
148
const captureConsoleIntegration = new CaptureConsole ( { levels : [ 'log' ] } ) ;
147
149
captureConsoleIntegration . setupOnce (
148
150
( ) => undefined ,
149
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
151
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
150
152
) ;
151
153
152
154
// call a wrapped function
@@ -162,7 +164,7 @@ describe('CaptureConsole setup', () => {
162
164
const captureConsoleIntegration = new CaptureConsole ( { levels : [ 'log' ] } ) ;
163
165
captureConsoleIntegration . setupOnce (
164
166
( ) => undefined ,
165
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
167
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
166
168
) ;
167
169
168
170
// call a wrapped function
@@ -181,7 +183,7 @@ describe('CaptureConsole setup', () => {
181
183
const captureConsoleIntegration = new CaptureConsole ( { levels : [ 'assert' ] } ) ;
182
184
captureConsoleIntegration . setupOnce (
183
185
( ) => undefined ,
184
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
186
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
185
187
) ;
186
188
187
189
global . console . assert ( 1 + 1 === 3 ) ;
@@ -195,7 +197,7 @@ describe('CaptureConsole setup', () => {
195
197
const captureConsoleIntegration = new CaptureConsole ( { levels : [ 'assert' ] } ) ;
196
198
captureConsoleIntegration . setupOnce (
197
199
( ) => undefined ,
198
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
200
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
199
201
) ;
200
202
201
203
global . console . assert ( 1 + 1 === 3 , 'expression is false' ) ;
@@ -209,7 +211,7 @@ describe('CaptureConsole setup', () => {
209
211
const captureConsoleIntegration = new CaptureConsole ( { levels : [ 'assert' ] } ) ;
210
212
captureConsoleIntegration . setupOnce (
211
213
( ) => undefined ,
212
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
214
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
213
215
) ;
214
216
215
217
global . console . assert ( 1 + 1 === 2 ) ;
@@ -219,7 +221,7 @@ describe('CaptureConsole setup', () => {
219
221
const captureConsoleIntegration = new CaptureConsole ( { levels : [ 'error' ] } ) ;
220
222
captureConsoleIntegration . setupOnce (
221
223
( ) => undefined ,
222
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
224
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
223
225
) ;
224
226
225
227
const someError = new Error ( 'some error' ) ;
@@ -233,7 +235,7 @@ describe('CaptureConsole setup', () => {
233
235
const captureConsoleIntegration = new CaptureConsole ( ) ;
234
236
captureConsoleIntegration . setupOnce (
235
237
( ) => undefined ,
236
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
238
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
237
239
) ;
238
240
239
241
const someError = new Error ( 'some error' ) ;
@@ -247,7 +249,7 @@ describe('CaptureConsole setup', () => {
247
249
const captureConsoleIntegration = new CaptureConsole ( ) ;
248
250
captureConsoleIntegration . setupOnce (
249
251
( ) => undefined ,
250
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
252
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
251
253
) ;
252
254
253
255
global . console . error ( 'some message' ) ;
@@ -260,7 +262,7 @@ describe('CaptureConsole setup', () => {
260
262
const captureConsoleIntegration = new CaptureConsole ( { levels : [ 'error' ] } ) ;
261
263
captureConsoleIntegration . setupOnce (
262
264
( ) => undefined ,
263
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
265
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
264
266
) ;
265
267
266
268
global . console . error ( 'some non-error message' ) ;
@@ -274,7 +276,7 @@ describe('CaptureConsole setup', () => {
274
276
const captureConsoleIntegration = new CaptureConsole ( { levels : [ 'info' ] } ) ;
275
277
captureConsoleIntegration . setupOnce (
276
278
( ) => undefined ,
277
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
279
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
278
280
) ;
279
281
280
282
global . console . info ( 'some message' ) ;
@@ -292,7 +294,7 @@ describe('CaptureConsole setup', () => {
292
294
const captureConsoleIntegration = new CaptureConsole ( { levels : [ 'log' ] } ) ;
293
295
captureConsoleIntegration . setupOnce (
294
296
( ) => undefined ,
295
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
297
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
296
298
) ;
297
299
298
300
global . console . log ( 'some message 1' , 'some message 2' ) ;
@@ -308,11 +310,11 @@ describe('CaptureConsole setup', () => {
308
310
const captureConsoleIntegration = new CaptureConsole ( { levels : [ 'log' , 'someNonExistingLevel' , 'error' ] } ) ;
309
311
captureConsoleIntegration . setupOnce (
310
312
( ) => undefined ,
311
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
313
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
312
314
) ;
313
315
314
316
// The provided level should not be created
315
- expect ( global . console [ 'someNonExistingLevel' ] ) . toBeUndefined ( ) ;
317
+ expect ( ( global . console as any ) [ 'someNonExistingLevel' ] ) . toBeUndefined ( ) ;
316
318
317
319
// Ohter levels should be wrapped as expected
318
320
expect ( global . console . log ) . not . toBe ( originalConsole . log ) ;
@@ -323,7 +325,7 @@ describe('CaptureConsole setup', () => {
323
325
const captureConsoleIntegration = new CaptureConsole ( { levels : [ 'log' , 'error' ] } ) ;
324
326
captureConsoleIntegration . setupOnce (
325
327
( ) => undefined ,
326
- ( ) => getMockHubWithIntegration ( null ) as any , // simulate not having the integration registered
328
+ ( ) => getMockHubWithIntegration ( null as any ) , // simulate not having the integration registered
327
329
) ;
328
330
329
331
// Console should be wrapped
@@ -337,12 +339,12 @@ describe('CaptureConsole setup', () => {
337
339
338
340
it ( "should not crash when the original console methods don't exist at time of invocation" , ( ) => {
339
341
const originalConsoleLog = global . console . log ;
340
- global . console . log = undefined ; // don't `delete` here, otherwise `fill` won't wrap the function
342
+ global . console . log = undefined as any ; // don't `delete` here, otherwise `fill` won't wrap the function
341
343
342
344
const captureConsoleIntegration = new CaptureConsole ( { levels : [ 'log' ] } ) ;
343
345
captureConsoleIntegration . setupOnce (
344
346
( ) => undefined ,
345
- ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) as any ,
347
+ ( ) => getMockHubWithIntegration ( captureConsoleIntegration ) ,
346
348
) ;
347
349
348
350
expect ( ( ) => {
0 commit comments