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.',
|
'Both GEMINI_API_KEY and GOOGLE_API_KEY are set. Using GOOGLE_API_KEY.',
|
||||||
);
|
);
|
||||||
expect(result.getApiKey()).toBe('google-key');
|
expect(result.getApiKey()).toBe('google-key');
|
||||||
|
|
||||||
consoleWarnSpy.mockRestore();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ describe('runNonInteractive', () => {
|
||||||
let mockProcessExit: ReturnType<typeof vi.fn>;
|
let mockProcessExit: ReturnType<typeof vi.fn>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
vi.resetAllMocks();
|
||||||
mockChat = {
|
mockChat = {
|
||||||
sendMessageStream: vi.fn(),
|
sendMessageStream: vi.fn(),
|
||||||
};
|
};
|
||||||
|
@ -201,7 +202,6 @@ describe('runNonInteractive', () => {
|
||||||
expect(mockProcessStdoutWrite).toHaveBeenCalledWith(
|
expect(mockProcessStdoutWrite).toHaveBeenCalledWith(
|
||||||
'Could not complete request.',
|
'Could not complete request.',
|
||||||
);
|
);
|
||||||
consoleErrorSpy.mockRestore();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should exit with error if sendMessageStream throws initially', async () => {
|
it('should exit with error if sendMessageStream throws initially', async () => {
|
||||||
|
@ -217,6 +217,5 @@ describe('runNonInteractive', () => {
|
||||||
'Error processing input:',
|
'Error processing input:',
|
||||||
apiError,
|
apiError,
|
||||||
);
|
);
|
||||||
consoleErrorSpy.mockRestore();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -74,8 +74,7 @@ describe('loadGeminiIgnorePatterns', () => {
|
||||||
if (actualFs.existsSync(tempDir)) {
|
if (actualFs.existsSync(tempDir)) {
|
||||||
actualFs.rmSync(tempDir, { recursive: true, force: true });
|
actualFs.rmSync(tempDir, { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
consoleLogSpy.mockRestore();
|
vi.restoreAllMocks();
|
||||||
consoleWarnSpy.mockRestore();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should load and parse patterns from .geminiignore, ignoring comments and empty lines', () => {
|
it('should load and parse patterns from .geminiignore, ignoring comments and empty lines', () => {
|
||||||
|
|
|
@ -82,12 +82,11 @@ describe('Logger', () => {
|
||||||
let logger: Logger;
|
let logger: Logger;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
vi.resetAllMocks();
|
||||||
vi.useFakeTimers();
|
vi.useFakeTimers();
|
||||||
vi.setSystemTime(new Date('2025-01-01T12:00:00.000Z'));
|
vi.setSystemTime(new Date('2025-01-01T12:00:00.000Z'));
|
||||||
await cleanupLogFile();
|
await cleanupLogFile();
|
||||||
logger = new Logger();
|
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();
|
await logger.initialize();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -95,7 +94,7 @@ describe('Logger', () => {
|
||||||
logger.close();
|
logger.close();
|
||||||
await cleanupLogFile();
|
await cleanupLogFile();
|
||||||
vi.useRealTimers();
|
vi.useRealTimers();
|
||||||
vi.resetAllMocks(); // Ensure mocks are reset for every test
|
vi.restoreAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
|
@ -221,7 +220,6 @@ describe('Logger', () => {
|
||||||
f.startsWith(LOG_FILE_NAME + '.invalid_json') && f.endsWith('.bak'),
|
f.startsWith(LOG_FILE_NAME + '.invalid_json') && f.endsWith('.bak'),
|
||||||
),
|
),
|
||||||
).toBe(true);
|
).toBe(true);
|
||||||
consoleDebugSpy.mockRestore();
|
|
||||||
newLogger.close();
|
newLogger.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -251,7 +249,6 @@ describe('Logger', () => {
|
||||||
f.endsWith('.bak'),
|
f.endsWith('.bak'),
|
||||||
),
|
),
|
||||||
).toBe(true);
|
).toBe(true);
|
||||||
consoleDebugSpy.mockRestore();
|
|
||||||
newLogger.close();
|
newLogger.close();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -295,7 +292,6 @@ describe('Logger', () => {
|
||||||
'Logger not initialized or session ID missing. Cannot log message.',
|
'Logger not initialized or session ID missing. Cannot log message.',
|
||||||
);
|
);
|
||||||
expect((await readLogFile()).length).toBe(0);
|
expect((await readLogFile()).length).toBe(0);
|
||||||
consoleDebugSpy.mockRestore();
|
|
||||||
uninitializedLogger.close();
|
uninitializedLogger.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -346,9 +342,7 @@ describe('Logger', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not throw, not increment messageId, and log error if writing to file fails', async () => {
|
it('should not throw, not increment messageId, and log error if writing to file fails', async () => {
|
||||||
const writeFileSpy = vi
|
vi.spyOn(fs, 'writeFile').mockRejectedValueOnce(new Error('Disk full'));
|
||||||
.spyOn(fs, 'writeFile')
|
|
||||||
.mockRejectedValueOnce(new Error('Disk full'));
|
|
||||||
const consoleDebugSpy = vi
|
const consoleDebugSpy = vi
|
||||||
.spyOn(console, 'debug')
|
.spyOn(console, 'debug')
|
||||||
.mockImplementation(() => {});
|
.mockImplementation(() => {});
|
||||||
|
@ -363,9 +357,6 @@ describe('Logger', () => {
|
||||||
);
|
);
|
||||||
expect(logger['messageId']).toBe(initialMessageId); // Not incremented
|
expect(logger['messageId']).toBe(initialMessageId); // Not incremented
|
||||||
expect(logger['logs'].length).toBe(initialLogCount); // Log not added to in-memory cache
|
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');
|
const fileContent = await fs.readFile(taggedFilePath, 'utf-8');
|
||||||
expect(JSON.parse(fileContent)).toEqual(conversation);
|
expect(JSON.parse(fileContent)).toEqual(conversation);
|
||||||
// cleanup
|
|
||||||
await fs.unlink(taggedFilePath);
|
await fs.unlink(taggedFilePath);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -464,7 +454,6 @@ describe('Logger', () => {
|
||||||
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
||||||
'Logger not initialized or checkpoint file path not set. Cannot save a checkpoint.',
|
'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.stringContaining('Failed to read or parse checkpoint file'),
|
||||||
expect.any(SyntaxError),
|
expect.any(SyntaxError),
|
||||||
);
|
);
|
||||||
consoleErrorSpy.mockRestore();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return an empty array if logger is not initialized', async () => {
|
it('should return an empty array if logger is not initialized', async () => {
|
||||||
|
@ -542,7 +530,6 @@ describe('Logger', () => {
|
||||||
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
||||||
'Logger not initialized or checkpoint file path not set. Cannot load checkpoint.',
|
'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['logs']).toEqual([]);
|
||||||
expect(logger['sessionId']).toBeUndefined();
|
expect(logger['sessionId']).toBeUndefined();
|
||||||
expect(logger['messageId']).toBe(0);
|
expect(logger['messageId']).toBe(0);
|
||||||
consoleDebugSpy.mockRestore();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -29,7 +29,6 @@ describe('reportError', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
consoleErrorSpy.mockRestore();
|
|
||||||
vi.restoreAllMocks();
|
vi.restoreAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -176,8 +176,6 @@ describe('retryWithBackoff', () => {
|
||||||
// The third delay should be capped by maxDelayMs (250ms), accounting for jitter
|
// The third delay should be capped by maxDelayMs (250ms), accounting for jitter
|
||||||
expect(delays[2]).toBeGreaterThanOrEqual(250 * 0.7);
|
expect(delays[2]).toBeGreaterThanOrEqual(250 * 0.7);
|
||||||
expect(delays[2]).toBeLessThanOrEqual(250 * 1.3);
|
expect(delays[2]).toBeLessThanOrEqual(250 * 1.3);
|
||||||
|
|
||||||
setTimeoutSpy.mockRestore();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle jitter correctly, ensuring varied delays', async () => {
|
it('should handle jitter correctly, ensuring varied delays', async () => {
|
||||||
|
@ -232,7 +230,5 @@ describe('retryWithBackoff', () => {
|
||||||
expect(d).toBeGreaterThanOrEqual(100 * 0.7);
|
expect(d).toBeGreaterThanOrEqual(100 * 0.7);
|
||||||
expect(d).toBeLessThanOrEqual(100 * 1.3);
|
expect(d).toBeLessThanOrEqual(100 * 1.3);
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeoutSpy.mockRestore();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue