Remove unneeded `mockRestore()`s from tests (#919)
This commit is contained in:
parent
3372fd8df8
commit
fb6e2927f7
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ describe('runNonInteractive', () => {
|
|||
let mockProcessExit: ReturnType<typeof vi.fn>;
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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', () => {
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -29,7 +29,6 @@ describe('reportError', () => {
|
|||
});
|
||||
|
||||
afterEach(() => {
|
||||
consoleErrorSpy.mockRestore();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue