diff --git a/packages/cli/src/config/config.test.ts b/packages/cli/src/config/config.test.ts index 1859943b..269b4c81 100644 --- a/packages/cli/src/config/config.test.ts +++ b/packages/cli/src/config/config.test.ts @@ -214,8 +214,6 @@ describe('API Key Handling', () => { 'Both GEMINI_API_KEY and GOOGLE_API_KEY are set. Using GOOGLE_API_KEY.', ); expect(result.getApiKey()).toBe('google-key'); - - consoleWarnSpy.mockRestore(); }); }); diff --git a/packages/cli/src/nonInteractiveCli.test.ts b/packages/cli/src/nonInteractiveCli.test.ts index c8fb1d33..4e7fd727 100644 --- a/packages/cli/src/nonInteractiveCli.test.ts +++ b/packages/cli/src/nonInteractiveCli.test.ts @@ -35,6 +35,7 @@ describe('runNonInteractive', () => { let mockProcessExit: ReturnType; beforeEach(() => { + vi.resetAllMocks(); mockChat = { sendMessageStream: vi.fn(), }; @@ -201,7 +202,6 @@ describe('runNonInteractive', () => { expect(mockProcessStdoutWrite).toHaveBeenCalledWith( 'Could not complete request.', ); - consoleErrorSpy.mockRestore(); }); it('should exit with error if sendMessageStream throws initially', async () => { @@ -217,6 +217,5 @@ describe('runNonInteractive', () => { 'Error processing input:', apiError, ); - consoleErrorSpy.mockRestore(); }); }); diff --git a/packages/cli/src/utils/loadIgnorePatterns.test.ts b/packages/cli/src/utils/loadIgnorePatterns.test.ts index dc746ab0..9bcddf34 100644 --- a/packages/cli/src/utils/loadIgnorePatterns.test.ts +++ b/packages/cli/src/utils/loadIgnorePatterns.test.ts @@ -74,8 +74,7 @@ describe('loadGeminiIgnorePatterns', () => { if (actualFs.existsSync(tempDir)) { actualFs.rmSync(tempDir, { recursive: true, force: true }); } - consoleLogSpy.mockRestore(); - consoleWarnSpy.mockRestore(); + vi.restoreAllMocks(); }); it('should load and parse patterns from .geminiignore, ignoring comments and empty lines', () => { diff --git a/packages/core/src/core/logger.test.ts b/packages/core/src/core/logger.test.ts index 72eb353e..d7bb8ef6 100644 --- a/packages/core/src/core/logger.test.ts +++ b/packages/core/src/core/logger.test.ts @@ -82,12 +82,11 @@ describe('Logger', () => { let logger: Logger; beforeEach(async () => { + vi.resetAllMocks(); vi.useFakeTimers(); vi.setSystemTime(new Date('2025-01-01T12:00:00.000Z')); await cleanupLogFile(); logger = new Logger(); - // Initialize is usually called here, but some tests initialize their own instances. - // For tests that use the global `logger`, it will be initialized here. await logger.initialize(); }); @@ -95,7 +94,7 @@ describe('Logger', () => { logger.close(); await cleanupLogFile(); vi.useRealTimers(); - vi.resetAllMocks(); // Ensure mocks are reset for every test + vi.restoreAllMocks(); }); afterAll(async () => { @@ -221,7 +220,6 @@ describe('Logger', () => { f.startsWith(LOG_FILE_NAME + '.invalid_json') && f.endsWith('.bak'), ), ).toBe(true); - consoleDebugSpy.mockRestore(); newLogger.close(); }); @@ -251,7 +249,6 @@ describe('Logger', () => { f.endsWith('.bak'), ), ).toBe(true); - consoleDebugSpy.mockRestore(); newLogger.close(); }); }); @@ -295,7 +292,6 @@ describe('Logger', () => { 'Logger not initialized or session ID missing. Cannot log message.', ); expect((await readLogFile()).length).toBe(0); - consoleDebugSpy.mockRestore(); uninitializedLogger.close(); }); @@ -346,9 +342,7 @@ describe('Logger', () => { }); it('should not throw, not increment messageId, and log error if writing to file fails', async () => { - const writeFileSpy = vi - .spyOn(fs, 'writeFile') - .mockRejectedValueOnce(new Error('Disk full')); + vi.spyOn(fs, 'writeFile').mockRejectedValueOnce(new Error('Disk full')); const consoleDebugSpy = vi .spyOn(console, 'debug') .mockImplementation(() => {}); @@ -363,9 +357,6 @@ describe('Logger', () => { ); expect(logger['messageId']).toBe(initialMessageId); // Not incremented expect(logger['logs'].length).toBe(initialLogCount); // Log not added to in-memory cache - - writeFileSpy.mockRestore(); - consoleDebugSpy.mockRestore(); }); }); @@ -448,7 +439,6 @@ describe('Logger', () => { ); const fileContent = await fs.readFile(taggedFilePath, 'utf-8'); expect(JSON.parse(fileContent)).toEqual(conversation); - // cleanup await fs.unlink(taggedFilePath); }); @@ -464,7 +454,6 @@ describe('Logger', () => { expect(consoleErrorSpy).toHaveBeenCalledWith( 'Logger not initialized or checkpoint file path not set. Cannot save a checkpoint.', ); - consoleErrorSpy.mockRestore(); }); }); @@ -529,7 +518,6 @@ describe('Logger', () => { expect.stringContaining('Failed to read or parse checkpoint file'), expect.any(SyntaxError), ); - consoleErrorSpy.mockRestore(); }); it('should return an empty array if logger is not initialized', async () => { @@ -542,7 +530,6 @@ describe('Logger', () => { expect(consoleErrorSpy).toHaveBeenCalledWith( 'Logger not initialized or checkpoint file path not set. Cannot load checkpoint.', ); - consoleErrorSpy.mockRestore(); }); }); @@ -564,7 +551,6 @@ describe('Logger', () => { expect(logger['logs']).toEqual([]); expect(logger['sessionId']).toBeUndefined(); expect(logger['messageId']).toBe(0); - consoleDebugSpy.mockRestore(); }); }); }); diff --git a/packages/core/src/utils/errorReporting.test.ts b/packages/core/src/utils/errorReporting.test.ts index 1faba5f6..8d1a5bab 100644 --- a/packages/core/src/utils/errorReporting.test.ts +++ b/packages/core/src/utils/errorReporting.test.ts @@ -29,7 +29,6 @@ describe('reportError', () => { }); afterEach(() => { - consoleErrorSpy.mockRestore(); vi.restoreAllMocks(); }); diff --git a/packages/core/src/utils/retry.test.ts b/packages/core/src/utils/retry.test.ts index ea344d60..4c269987 100644 --- a/packages/core/src/utils/retry.test.ts +++ b/packages/core/src/utils/retry.test.ts @@ -176,8 +176,6 @@ describe('retryWithBackoff', () => { // The third delay should be capped by maxDelayMs (250ms), accounting for jitter expect(delays[2]).toBeGreaterThanOrEqual(250 * 0.7); expect(delays[2]).toBeLessThanOrEqual(250 * 1.3); - - setTimeoutSpy.mockRestore(); }); it('should handle jitter correctly, ensuring varied delays', async () => { @@ -232,7 +230,5 @@ describe('retryWithBackoff', () => { expect(d).toBeGreaterThanOrEqual(100 * 0.7); expect(d).toBeLessThanOrEqual(100 * 1.3); }); - - setTimeoutSpy.mockRestore(); }); });