fix test to use faketimer (#12913)

This commit is contained in:
Tommaso Sciortino
2025-11-11 19:03:10 -08:00
committed by GitHub
parent 2abc288c52
commit e8038c727f
+13 -6
View File
@@ -39,11 +39,22 @@ describe('FixLLMEditWithInstruction', () => {
beforeEach(() => {
vi.useFakeTimers();
vi.clearAllMocks();
// Mock AbortSignal.timeout to use setTimeout so it respects fake timers
vi.spyOn(AbortSignal, 'timeout').mockImplementation((ms) => {
const controller = new AbortController();
setTimeout(
() =>
controller.abort(new DOMException('TimeoutError', 'TimeoutError')),
ms,
);
return controller.signal;
});
resetLlmEditFixerCaches_TEST_ONLY(); // Ensure cache is cleared before each test
});
afterEach(() => {
vi.useRealTimers(); // Reset timers after each test
vi.restoreAllMocks();
});
const mockApiResponse: SearchReplaceEdit = {
@@ -329,10 +340,7 @@ describe('FixLLMEditWithInstruction', () => {
});
});
it(
'should return null if the LLM call times out',
{ timeout: 60000 },
async () => {
it('should return null if the LLM call times out', async () => {
mockGenerateJson.mockImplementation(
async ({ abortSignal }) =>
// Simulate a long-running operation that never resolves on its own.
@@ -368,6 +376,5 @@ describe('FixLLMEditWithInstruction', () => {
expect(result).toBeNull();
expect(mockGenerateJson).toHaveBeenCalledOnce();
},
);
});
});