address feedback

This commit is contained in:
Nate 2025-08-02 19:36:56 -04:00
parent c621961f8d
commit 70956fbcf3
4 changed files with 33 additions and 8 deletions

View file

@ -15,7 +15,7 @@ describe('ApiClientService', () => {
};
beforeEach(() => {
vi.clearAllMocks();
vi.resetAllMocks();
service = new ApiClientService();
});

View file

@ -38,7 +38,9 @@ export abstract class BaseService<TState> 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';
}

View file

@ -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`);

View file

@ -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: [