@@ -2,7 +2,7 @@ import type { ClientOptions, EventProcessor } from '@sentry/types';
2
2
import type { LRUMap } from '@sentry/utils' ;
3
3
import type { Debugger , InspectorNotification } from 'inspector' ;
4
4
5
- import { defaultStackParser } from '../../src' ;
5
+ import { NodeClient , defaultStackParser } from '../../src' ;
6
6
import type { DebugSession , FrameVariables } from '../../src/integrations/localvariables' ;
7
7
import { LocalVariables , createCallbackList , createRateLimiter } from '../../src/integrations/localvariables' ;
8
8
import { NODE_VERSION } from '../../src/nodeVersion' ;
@@ -52,7 +52,6 @@ class MockDebugSession implements DebugSession {
52
52
53
53
interface LocalVariablesPrivate {
54
54
_cachedFrames : LRUMap < string , FrameVariables [ ] > ;
55
- _setup ( addGlobalEventProcessor : ( callback : EventProcessor ) => void , clientOptions : ClientOptions ) : void ;
56
55
}
57
56
58
57
const exceptionEvent = {
@@ -154,8 +153,6 @@ const exceptionEvent100Frames = {
154
153
155
154
describeIf ( ( NODE_VERSION . major || 0 ) >= 18 ) ( 'LocalVariables' , ( ) => {
156
155
it ( 'Adds local variables to stack frames' , async ( ) => {
157
- expect . assertions ( 7 ) ;
158
-
159
156
const session = new MockDebugSession ( {
160
157
'-6224981551105448869.1.2' : { name : 'tim' } ,
161
158
'-6224981551105448869.1.6' : { arr : [ 1 , 2 , 3 ] } ,
@@ -164,13 +161,14 @@ describeIf((NODE_VERSION.major || 0) >= 18)('LocalVariables', () => {
164
161
const options = getDefaultNodeClientOptions ( {
165
162
stackParser : defaultStackParser ,
166
163
includeLocalVariables : true ,
164
+ integrations : [ localVariables ] ,
167
165
} ) ;
168
166
169
- let eventProcessor : EventProcessor | undefined ;
167
+ const client = new NodeClient ( options ) ;
168
+ client . setupIntegrations ( true ) ;
170
169
171
- ( localVariables as unknown as LocalVariablesPrivate ) . _setup ( callback => {
172
- eventProcessor = callback ;
173
- } , options ) ;
170
+ const eventProcessors = client [ '_eventProcessors' ] ;
171
+ const eventProcessor = eventProcessors . find ( processor => processor . id === 'LocalVariables' ) ;
174
172
175
173
expect ( eventProcessor ) . toBeDefined ( ) ;
176
174
@@ -189,7 +187,7 @@ describeIf((NODE_VERSION.major || 0) >= 18)('LocalVariables', () => {
189
187
{ function : 'one' , vars : { arr : [ 1 , 2 , 3 ] } } ,
190
188
] ) ;
191
189
192
- const event = await eventProcessor ?. (
190
+ const event = await eventProcessor ! (
193
191
{
194
192
event_id : '9cbf882ade9a415986632ac4e16918eb' ,
195
193
platform : 'node' ,
@@ -249,22 +247,16 @@ describeIf((NODE_VERSION.major || 0) >= 18)('LocalVariables', () => {
249
247
} ) ;
250
248
251
249
it ( 'Only considers the first 5 frames' , async ( ) => {
252
- expect . assertions ( 4 ) ;
253
-
254
250
const session = new MockDebugSession ( { } ) ;
255
251
const localVariables = new LocalVariables ( { } , session ) ;
256
252
const options = getDefaultNodeClientOptions ( {
257
253
stackParser : defaultStackParser ,
258
254
includeLocalVariables : true ,
255
+ integrations : [ localVariables ] ,
259
256
} ) ;
260
257
261
- let eventProcessor : EventProcessor | undefined ;
262
-
263
- ( localVariables as unknown as LocalVariablesPrivate ) . _setup ( callback => {
264
- eventProcessor = callback ;
265
- } , options ) ;
266
-
267
- expect ( eventProcessor ) . toBeDefined ( ) ;
258
+ const client = new NodeClient ( options ) ;
259
+ client . setupIntegrations ( true ) ;
268
260
269
261
await session . runPause ( exceptionEvent100Frames ) ;
270
262
@@ -280,16 +272,16 @@ describeIf((NODE_VERSION.major || 0) >= 18)('LocalVariables', () => {
280
272
} ) ;
281
273
282
274
it ( 'Should not lookup variables for non-exception reasons' , async ( ) => {
283
- expect . assertions ( 1 ) ;
284
-
285
275
const session = new MockDebugSession ( { } , { getLocalVariables : true } ) ;
286
276
const localVariables = new LocalVariables ( { } , session ) ;
287
277
const options = getDefaultNodeClientOptions ( {
288
278
stackParser : defaultStackParser ,
289
279
includeLocalVariables : true ,
280
+ integrations : [ localVariables ] ,
290
281
} ) ;
291
282
292
- ( localVariables as unknown as LocalVariablesPrivate ) . _setup ( _ => { } , options ) ;
283
+ const client = new NodeClient ( options ) ;
284
+ client . setupIntegrations ( true ) ;
293
285
294
286
const nonExceptionEvent = {
295
287
method : exceptionEvent . method ,
@@ -302,43 +294,41 @@ describeIf((NODE_VERSION.major || 0) >= 18)('LocalVariables', () => {
302
294
} ) ;
303
295
304
296
it ( 'Should not initialize when disabled' , async ( ) => {
305
- expect . assertions ( 1 ) ;
306
-
307
297
const session = new MockDebugSession ( { } , { configureAndConnect : true } ) ;
308
298
const localVariables = new LocalVariables ( { } , session ) ;
309
299
const options = getDefaultNodeClientOptions ( {
310
300
stackParser : defaultStackParser ,
301
+ integrations : [ localVariables ] ,
311
302
} ) ;
312
303
313
- let eventProcessor : EventProcessor | undefined ;
304
+ const client = new NodeClient ( options ) ;
305
+ client . setupIntegrations ( true ) ;
314
306
315
- ( localVariables as unknown as LocalVariablesPrivate ) . _setup ( callback => {
316
- eventProcessor = callback ;
317
- } , options ) ;
307
+ const eventProcessors = client [ '_eventProcessors' ] ;
308
+ const eventProcessor = eventProcessors . find ( processor => processor . id === 'LocalVariables' ) ;
318
309
319
- expect ( eventProcessor ) . toBeUndefined ( ) ;
310
+ expect ( eventProcessor ) . toBeDefined ( ) ;
311
+ expect ( localVariables [ '_shouldProcessEvent' ] ) . toBe ( false ) ;
320
312
} ) ;
321
313
322
314
it ( 'Should not initialize when inspector not loaded' , async ( ) => {
323
- expect . assertions ( 1 ) ;
324
-
325
315
const localVariables = new LocalVariables ( { } , undefined ) ;
326
316
const options = getDefaultNodeClientOptions ( {
327
317
stackParser : defaultStackParser ,
318
+ integrations : [ localVariables ] ,
328
319
} ) ;
329
320
330
- let eventProcessor : EventProcessor | undefined ;
321
+ const client = new NodeClient ( options ) ;
322
+ client . setupIntegrations ( true ) ;
331
323
332
- ( localVariables as unknown as LocalVariablesPrivate ) . _setup ( callback => {
333
- eventProcessor = callback ;
334
- } , options ) ;
324
+ const eventProcessors = client [ '_eventProcessors' ] ;
325
+ const eventProcessor = eventProcessors . find ( processor => processor . id === 'LocalVariables' ) ;
335
326
336
- expect ( eventProcessor ) . toBeUndefined ( ) ;
327
+ expect ( eventProcessor ) . toBeDefined ( ) ;
328
+ expect ( localVariables [ '_shouldProcessEvent' ] ) . toBe ( false ) ;
337
329
} ) ;
338
330
339
331
it ( 'Should cache identical uncaught exception events' , async ( ) => {
340
- expect . assertions ( 1 ) ;
341
-
342
332
const session = new MockDebugSession ( {
343
333
'-6224981551105448869.1.2' : { name : 'tim' } ,
344
334
'-6224981551105448869.1.6' : { arr : [ 1 , 2 , 3 ] } ,
@@ -347,9 +337,11 @@ describeIf((NODE_VERSION.major || 0) >= 18)('LocalVariables', () => {
347
337
const options = getDefaultNodeClientOptions ( {
348
338
stackParser : defaultStackParser ,
349
339
includeLocalVariables : true ,
340
+ integrations : [ localVariables ] ,
350
341
} ) ;
351
342
352
- ( localVariables as unknown as LocalVariablesPrivate ) . _setup ( _ => { } , options ) ;
343
+ const client = new NodeClient ( options ) ;
344
+ client . setupIntegrations ( true ) ;
353
345
354
346
await session . runPause ( exceptionEvent ) ;
355
347
await session . runPause ( exceptionEvent ) ;
0 commit comments