Skip to content

Commit a7f98f1

Browse files
committed
Fix tests
1 parent f629f06 commit a7f98f1

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

packages/node/src/integrations/local-variables/local-variables-sync.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ export const localVariablesSync: IntegrationFn = (
217217
options: Options = {},
218218
session: DebugSession | undefined = tryNewAsyncSession(),
219219
) => {
220-
const _cachedFrames: LRUMap<string, FrameVariables[]> = new LRUMap(20);
220+
const cachedFrames: LRUMap<string, FrameVariables[]> = new LRUMap(20);
221221
let rateLimiter: RateLimitIncrement | undefined;
222222
let shouldProcessEvent = false;
223223

@@ -242,7 +242,7 @@ export const localVariablesSync: IntegrationFn = (
242242
}
243243

244244
const { add, next } = createCallbackList<FrameVariables[]>(frames => {
245-
_cachedFrames.set(exceptionHash, frames);
245+
cachedFrames.set(exceptionHash, frames);
246246
complete();
247247
});
248248

@@ -284,7 +284,7 @@ export const localVariablesSync: IntegrationFn = (
284284

285285
// Check if we have local variables for an exception that matches the hash
286286
// remove is identical to get but also removes the entry from the cache
287-
const cachedFrame = _cachedFrames.remove(hash);
287+
const cachedFrame = cachedFrames.remove(hash);
288288

289289
if (cachedFrame === undefined) {
290290
return;
@@ -375,6 +375,13 @@ export const localVariablesSync: IntegrationFn = (
375375

376376
return event;
377377
},
378+
// These are entirely for testing
379+
_getCachedFramesCount(): number {
380+
return cachedFrames.size;
381+
},
382+
_getFirstCachedFrame(): FrameVariables[] | undefined {
383+
return cachedFrames.values()[0];
384+
},
378385
};
379386
};
380387

packages/node/test/integrations/localvariables.test.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import type { LRUMap } from '@sentry/utils';
21
import type { Debugger, InspectorNotification } from 'inspector';
32

43
import { NodeClient, defaultStackParser } from '../../src';
5-
import { createRateLimiter } from '../../src/integrations/localvariables/common';
6-
import type { FrameVariables } from '../../src/integrations/localvariables/common';
7-
import type { DebugSession } from '../../src/integrations/localvariables/localvariables-sync';
8-
import { LocalVariablesSync, createCallbackList } from '../../src/integrations/localvariables/localvariables-sync';
4+
import { createRateLimiter } from '../../src/integrations/local-variables/common';
5+
import type { FrameVariables } from '../../src/integrations/local-variables/common';
6+
import type { DebugSession } from '../../src/integrations/local-variables/local-variables-sync';
7+
import { LocalVariablesSync, createCallbackList } from '../../src/integrations/local-variables/local-variables-sync';
98
import { NODE_VERSION } from '../../src/nodeVersion';
109
import { getDefaultNodeClientOptions } from '../../test/helper/node-client-options';
1110

@@ -52,7 +51,8 @@ class MockDebugSession implements DebugSession {
5251
}
5352

5453
interface LocalVariablesPrivate {
55-
_cachedFrames: LRUMap<string, FrameVariables[]>;
54+
_getCachedFramesCount(): number;
55+
_getFirstCachedFrame(): FrameVariables[] | undefined;
5656
}
5757

5858
const exceptionEvent = {
@@ -175,9 +175,9 @@ describeIf(NODE_VERSION.major >= 18)('LocalVariables', () => {
175175

176176
await session.runPause(exceptionEvent);
177177

178-
expect((localVariables as unknown as LocalVariablesPrivate)._cachedFrames.size).toBe(1);
178+
expect((localVariables as unknown as LocalVariablesPrivate)._getCachedFramesCount()).toBe(1);
179179

180-
const frames: FrameVariables[] = (localVariables as unknown as LocalVariablesPrivate)._cachedFrames.values()[0];
180+
const frames = (localVariables as unknown as LocalVariablesPrivate)._getFirstCachedFrame();
181181

182182
expect(frames).toBeDefined();
183183

@@ -244,7 +244,7 @@ describeIf(NODE_VERSION.major >= 18)('LocalVariables', () => {
244244
expect(event?.exception?.values?.[0].stacktrace?.frames?.[3]?.vars).toEqual({ arr: [1, 2, 3] });
245245
expect(event?.exception?.values?.[0].stacktrace?.frames?.[4]?.vars).toEqual({ name: 'tim' });
246246

247-
expect((localVariables as unknown as LocalVariablesPrivate)._cachedFrames.size).toBe(0);
247+
expect((localVariables as unknown as LocalVariablesPrivate)._getCachedFramesCount()).toBe(0);
248248
});
249249

250250
it('Only considers the first 5 frames', async () => {
@@ -261,9 +261,9 @@ describeIf(NODE_VERSION.major >= 18)('LocalVariables', () => {
261261

262262
await session.runPause(exceptionEvent100Frames);
263263

264-
expect((localVariables as unknown as LocalVariablesPrivate)._cachedFrames.size).toBe(1);
264+
expect((localVariables as unknown as LocalVariablesPrivate)._getCachedFramesCount()).toBe(1);
265265

266-
const frames: FrameVariables[] = (localVariables as unknown as LocalVariablesPrivate)._cachedFrames.values()[0];
266+
const frames = (localVariables as unknown as LocalVariablesPrivate)._getFirstCachedFrame();
267267

268268
expect(frames).toBeDefined();
269269

@@ -291,7 +291,7 @@ describeIf(NODE_VERSION.major >= 18)('LocalVariables', () => {
291291

292292
await session.runPause(nonExceptionEvent);
293293

294-
expect((localVariables as unknown as LocalVariablesPrivate)._cachedFrames.size).toBe(0);
294+
expect((localVariables as unknown as LocalVariablesPrivate)._getCachedFramesCount()).toBe(0);
295295
});
296296

297297
it('Should not initialize when disabled', async () => {
@@ -309,7 +309,6 @@ describeIf(NODE_VERSION.major >= 18)('LocalVariables', () => {
309309
const eventProcessor = eventProcessors.find(processor => processor.id === 'LocalVariablesSync');
310310

311311
expect(eventProcessor).toBeDefined();
312-
expect(localVariables['_shouldProcessEvent']).toBe(false);
313312
});
314313

315314
it('Should not initialize when inspector not loaded', async () => {
@@ -326,7 +325,6 @@ describeIf(NODE_VERSION.major >= 18)('LocalVariables', () => {
326325
const eventProcessor = eventProcessors.find(processor => processor.id === 'LocalVariablesSync');
327326

328327
expect(eventProcessor).toBeDefined();
329-
expect(localVariables['_shouldProcessEvent']).toBe(false);
330328
});
331329

332330
it('Should cache identical uncaught exception events', async () => {
@@ -350,7 +348,7 @@ describeIf(NODE_VERSION.major >= 18)('LocalVariables', () => {
350348
await session.runPause(exceptionEvent);
351349
await session.runPause(exceptionEvent);
352350

353-
expect((localVariables as unknown as LocalVariablesPrivate)._cachedFrames.size).toBe(1);
351+
expect((localVariables as unknown as LocalVariablesPrivate)._getCachedFramesCount()).toBe(1);
354352
});
355353

356354
describe('createCallbackList', () => {

0 commit comments

Comments
 (0)