@@ -2,7 +2,7 @@ import type { ClientOptions, EventProcessor } from '@sentry/types';
22import type { LRUMap } from '@sentry/utils' ;
33import type { Debugger , InspectorNotification } from 'inspector' ;
44
5- import { defaultStackParser } from '../../src' ;
5+ import { NodeClient , defaultStackParser } from '../../src' ;
66import type { DebugSession , FrameVariables } from '../../src/integrations/localvariables' ;
77import { LocalVariables , createCallbackList , createRateLimiter } from '../../src/integrations/localvariables' ;
88import { NODE_VERSION } from '../../src/nodeVersion' ;
@@ -52,7 +52,6 @@ class MockDebugSession implements DebugSession {
5252
5353interface LocalVariablesPrivate {
5454 _cachedFrames : LRUMap < string , FrameVariables [ ] > ;
55- _setup ( addGlobalEventProcessor : ( callback : EventProcessor ) => void , clientOptions : ClientOptions ) : void ;
5655}
5756
5857const exceptionEvent = {
@@ -154,8 +153,6 @@ const exceptionEvent100Frames = {
154153
155154describeIf ( ( NODE_VERSION . major || 0 ) >= 18 ) ( 'LocalVariables' , ( ) => {
156155 it ( 'Adds local variables to stack frames' , async ( ) => {
157- expect . assertions ( 7 ) ;
158-
159156 const session = new MockDebugSession ( {
160157 '-6224981551105448869.1.2' : { name : 'tim' } ,
161158 '-6224981551105448869.1.6' : { arr : [ 1 , 2 , 3 ] } ,
@@ -164,13 +161,14 @@ describeIf((NODE_VERSION.major || 0) >= 18)('LocalVariables', () => {
164161 const options = getDefaultNodeClientOptions ( {
165162 stackParser : defaultStackParser ,
166163 includeLocalVariables : true ,
164+ integrations : [ localVariables ] ,
167165 } ) ;
168166
169- let eventProcessor : EventProcessor | undefined ;
167+ const client = new NodeClient ( options ) ;
168+ client . setupIntegrations ( true ) ;
170169
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' ) ;
174172
175173 expect ( eventProcessor ) . toBeDefined ( ) ;
176174
@@ -189,7 +187,7 @@ describeIf((NODE_VERSION.major || 0) >= 18)('LocalVariables', () => {
189187 { function : 'one' , vars : { arr : [ 1 , 2 , 3 ] } } ,
190188 ] ) ;
191189
192- const event = await eventProcessor ?. (
190+ const event = await eventProcessor ! (
193191 {
194192 event_id : '9cbf882ade9a415986632ac4e16918eb' ,
195193 platform : 'node' ,
@@ -249,22 +247,16 @@ describeIf((NODE_VERSION.major || 0) >= 18)('LocalVariables', () => {
249247 } ) ;
250248
251249 it ( 'Only considers the first 5 frames' , async ( ) => {
252- expect . assertions ( 4 ) ;
253-
254250 const session = new MockDebugSession ( { } ) ;
255251 const localVariables = new LocalVariables ( { } , session ) ;
256252 const options = getDefaultNodeClientOptions ( {
257253 stackParser : defaultStackParser ,
258254 includeLocalVariables : true ,
255+ integrations : [ localVariables ] ,
259256 } ) ;
260257
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 ) ;
268260
269261 await session . runPause ( exceptionEvent100Frames ) ;
270262
@@ -280,16 +272,16 @@ describeIf((NODE_VERSION.major || 0) >= 18)('LocalVariables', () => {
280272 } ) ;
281273
282274 it ( 'Should not lookup variables for non-exception reasons' , async ( ) => {
283- expect . assertions ( 1 ) ;
284-
285275 const session = new MockDebugSession ( { } , { getLocalVariables : true } ) ;
286276 const localVariables = new LocalVariables ( { } , session ) ;
287277 const options = getDefaultNodeClientOptions ( {
288278 stackParser : defaultStackParser ,
289279 includeLocalVariables : true ,
280+ integrations : [ localVariables ] ,
290281 } ) ;
291282
292- ( localVariables as unknown as LocalVariablesPrivate ) . _setup ( _ => { } , options ) ;
283+ const client = new NodeClient ( options ) ;
284+ client . setupIntegrations ( true ) ;
293285
294286 const nonExceptionEvent = {
295287 method : exceptionEvent . method ,
@@ -302,43 +294,41 @@ describeIf((NODE_VERSION.major || 0) >= 18)('LocalVariables', () => {
302294 } ) ;
303295
304296 it ( 'Should not initialize when disabled' , async ( ) => {
305- expect . assertions ( 1 ) ;
306-
307297 const session = new MockDebugSession ( { } , { configureAndConnect : true } ) ;
308298 const localVariables = new LocalVariables ( { } , session ) ;
309299 const options = getDefaultNodeClientOptions ( {
310300 stackParser : defaultStackParser ,
301+ integrations : [ localVariables ] ,
311302 } ) ;
312303
313- let eventProcessor : EventProcessor | undefined ;
304+ const client = new NodeClient ( options ) ;
305+ client . setupIntegrations ( true ) ;
314306
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' ) ;
318309
319- expect ( eventProcessor ) . toBeUndefined ( ) ;
310+ expect ( eventProcessor ) . toBeDefined ( ) ;
311+ expect ( localVariables [ '_shouldProcessEvent' ] ) . toBe ( false ) ;
320312 } ) ;
321313
322314 it ( 'Should not initialize when inspector not loaded' , async ( ) => {
323- expect . assertions ( 1 ) ;
324-
325315 const localVariables = new LocalVariables ( { } , undefined ) ;
326316 const options = getDefaultNodeClientOptions ( {
327317 stackParser : defaultStackParser ,
318+ integrations : [ localVariables ] ,
328319 } ) ;
329320
330- let eventProcessor : EventProcessor | undefined ;
321+ const client = new NodeClient ( options ) ;
322+ client . setupIntegrations ( true ) ;
331323
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' ) ;
335326
336- expect ( eventProcessor ) . toBeUndefined ( ) ;
327+ expect ( eventProcessor ) . toBeDefined ( ) ;
328+ expect ( localVariables [ '_shouldProcessEvent' ] ) . toBe ( false ) ;
337329 } ) ;
338330
339331 it ( 'Should cache identical uncaught exception events' , async ( ) => {
340- expect . assertions ( 1 ) ;
341-
342332 const session = new MockDebugSession ( {
343333 '-6224981551105448869.1.2' : { name : 'tim' } ,
344334 '-6224981551105448869.1.6' : { arr : [ 1 , 2 , 3 ] } ,
@@ -347,9 +337,11 @@ describeIf((NODE_VERSION.major || 0) >= 18)('LocalVariables', () => {
347337 const options = getDefaultNodeClientOptions ( {
348338 stackParser : defaultStackParser ,
349339 includeLocalVariables : true ,
340+ integrations : [ localVariables ] ,
350341 } ) ;
351342
352- ( localVariables as unknown as LocalVariablesPrivate ) . _setup ( _ => { } , options ) ;
343+ const client = new NodeClient ( options ) ;
344+ client . setupIntegrations ( true ) ;
353345
354346 await session . runPause ( exceptionEvent ) ;
355347 await session . runPause ( exceptionEvent ) ;
0 commit comments