From a1ebb6f2756bfe9bbeac28dedda8668ca465d3ac Mon Sep 17 00:00:00 2001 From: fuyou Date: Wed, 17 Sep 2025 00:09:08 +0800 Subject: [PATCH] Fix Windows CI flaky test in SettingsDialog.test.tsx (#8533) Co-authored-by: Tommaso Sciortino --- .../src/ui/components/SettingsDialog.test.tsx | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packages/cli/src/ui/components/SettingsDialog.test.tsx b/packages/cli/src/ui/components/SettingsDialog.test.tsx index 1062442a2a..43f95e5e6c 100644 --- a/packages/cli/src/ui/components/SettingsDialog.test.tsx +++ b/packages/cli/src/ui/components/SettingsDialog.test.tsx @@ -307,6 +307,8 @@ describe('SettingsDialog', () => { describe('Settings Toggling', () => { it('should toggle setting with Enter key', async () => { + vi.mocked(saveModifiedSettings).mockClear(); + const settings = createMockSettings(); const onSelect = vi.fn(); const component = ( @@ -323,6 +325,14 @@ describe('SettingsDialog', () => { stdin.write(TerminalKeys.ENTER as string); await wait(); + // Wait for the mock to be called with more generous timeout for Windows + await waitFor( + () => { + expect(vi.mocked(saveModifiedSettings)).toHaveBeenCalled(); + }, + { timeout: 1000 }, + ); + expect(vi.mocked(saveModifiedSettings)).toHaveBeenCalledWith( new Set(['general.disableAutoUpdate']), { @@ -380,6 +390,8 @@ describe('SettingsDialog', () => { } as unknown as SettingsSchemaType; it('toggles enum values with the enter key', async () => { + vi.mocked(saveModifiedSettings).mockClear(); + vi.mocked(getSettingsSchema).mockReturnValue(FAKE_SCHEMA); const settings = createMockSettings(); const onSelect = vi.fn(); @@ -396,6 +408,12 @@ describe('SettingsDialog', () => { await wait(); stdin.write(TerminalKeys.ENTER as string); await wait(); + await waitFor( + () => { + expect(vi.mocked(saveModifiedSettings)).toHaveBeenCalled(); + }, + { timeout: 1000 }, + ); expect(vi.mocked(saveModifiedSettings)).toHaveBeenCalledWith( new Set(['ui.theme']), @@ -412,6 +430,7 @@ describe('SettingsDialog', () => { }); it('loops back when reaching the end of an enum', async () => { + vi.mocked(saveModifiedSettings).mockClear(); vi.mocked(getSettingsSchema).mockReturnValue(FAKE_SCHEMA); const settings = createMockSettings(); settings.setValue(SettingScope.User, 'ui.theme', StringEnum.BAZ); @@ -429,6 +448,12 @@ describe('SettingsDialog', () => { await wait(); stdin.write(TerminalKeys.ENTER as string); await wait(); + await waitFor( + () => { + expect(vi.mocked(saveModifiedSettings)).toHaveBeenCalled(); + }, + { timeout: 1000 }, + ); expect(vi.mocked(saveModifiedSettings)).toHaveBeenCalledWith( new Set(['ui.theme']),