From 70956fbcf3f04702d81f5e658fb3aeeaba840697 Mon Sep 17 00:00:00 2001 From: Nate Date: Sat, 2 Aug 2025 19:36:56 -0400 Subject: [PATCH] address feedback --- src/services/ApiClientService.test.ts | 2 +- src/services/BaseService.ts | 6 ++++-- src/ui/__tests__/throttledGlob.test.ts | 27 +++++++++++++++++++++----- vitest.config.ts | 6 ++++++ 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/services/ApiClientService.test.ts b/src/services/ApiClientService.test.ts index f557a2cf8..00aeeb89d 100644 --- a/src/services/ApiClientService.test.ts +++ b/src/services/ApiClientService.test.ts @@ -15,7 +15,7 @@ describe('ApiClientService', () => { }; beforeEach(() => { - vi.clearAllMocks(); + vi.resetAllMocks(); service = new ApiClientService(); }); diff --git a/src/services/BaseService.ts b/src/services/BaseService.ts index b482b3da4..8f298965d 100644 --- a/src/services/BaseService.ts +++ b/src/services/BaseService.ts @@ -38,7 +38,9 @@ export abstract class BaseService extends EventEmitter { return state; } catch (error: any) { logger.error(`Failed to initialize ${this.serviceName}:`, error); - this.emit('error', error); + if (this.listenerCount('error') > 0) { + this.emit('error', error); + } throw error; } } @@ -117,5 +119,5 @@ export interface ServiceWithDependencies { * Helper to check if a service has dependencies */ export function hasDependencies(service: any): service is ServiceWithDependencies { - return typeof service.getDependencies === 'function'; + return service != null && typeof service.getDependencies === 'function'; } \ No newline at end of file diff --git a/src/ui/__tests__/throttledGlob.test.ts b/src/ui/__tests__/throttledGlob.test.ts index ba2a4819f..e07382fdc 100644 --- a/src/ui/__tests__/throttledGlob.test.ts +++ b/src/ui/__tests__/throttledGlob.test.ts @@ -22,10 +22,17 @@ let mockEventEmitter: MockGlobEmitter; vi.mock("glob", () => { return { stream: vi.fn(() => { + // Return the stored mock event emitter if it exists + if (mockEventEmitter) { + return mockEventEmitter; + } + + // Otherwise create a new one const EventEmitter = require("events").EventEmitter; - const emitter = new EventEmitter(); + const emitter = new EventEmitter() as MockGlobEmitter; emitter.pause = vi.fn().mockReturnValue(emitter); emitter.resume = vi.fn().mockReturnValue(emitter); + mockEventEmitter = emitter; return emitter; }), }; @@ -37,10 +44,8 @@ describe.skip("throttledGlob", () => { vi.useFakeTimers(); vi.clearAllMocks(); - // Get the glob module and create a fresh mock event emitter - const globModule = await import("glob"); - const streamFn = globModule.stream as any; - mockEventEmitter = streamFn(); + // Reset the mock event emitter for each test + mockEventEmitter = null as any; }); afterEach(() => { @@ -55,6 +60,9 @@ describe.skip("throttledGlob", () => { // Start the throttledGlob operation const promise = throttledGlob(patterns, options); + // The mock event emitter is now created by the first call to glob.stream() + expect(mockEventEmitter).toBeTruthy(); + // Emit file events mockFiles.forEach((file) => { mockEventEmitter.emit("data", file); @@ -79,6 +87,9 @@ describe.skip("throttledGlob", () => { // Start the throttledGlob operation const promise = throttledGlob(patterns, options, batchSize, delay); + // The mock event emitter is now created by the first call to glob.stream() + expect(mockEventEmitter).toBeTruthy(); + // Emit enough files to trigger throttling for (let i = 0; i < batchSize + 1; i++) { mockEventEmitter.emit("data", `file${i}.ts`); @@ -111,6 +122,9 @@ describe.skip("throttledGlob", () => { // Start the throttledGlob operation const promise = throttledGlob(patterns, options); + // The mock event emitter is now created by the first call to glob.stream() + expect(mockEventEmitter).toBeTruthy(); + // Emit an error event mockEventEmitter.emit("error", error); @@ -132,6 +146,9 @@ describe.skip("throttledGlob", () => { customDelay ); + // The mock event emitter is now created by the first call to glob.stream() + expect(mockEventEmitter).toBeTruthy(); + // Emit enough files to trigger throttling twice for (let i = 0; i < customBatchSize * 2; i++) { mockEventEmitter.emit("data", `file${i}.ts`); diff --git a/vitest.config.ts b/vitest.config.ts index bb223e7fd..d393f2a0a 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -5,6 +5,12 @@ export default defineConfig({ globals: true, environment: 'node', setupFiles: ['./vitest.setup.ts'], + exclude: [ + '**/node_modules/**', + '**/dist/**', + '**/*.e2e.*', + '**/e2e/**', + ], coverage: { reporter: ['text', 'json', 'html'], exclude: [