diff --git a/packages/cli/src/test-utils/render.tsx b/packages/cli/src/test-utils/render.tsx index 9dd0f96758..95a9965c04 100644 --- a/packages/cli/src/test-utils/render.tsx +++ b/packages/cli/src/test-utils/render.tsx @@ -340,9 +340,11 @@ class XtermStdin extends EventEmitter { } write = (data: string) => { - this.data = data; - this.emit('readable'); - this.emit('data', data); + act(() => { + this.data = data; + this.emit('readable'); + this.emit('data', data); + }); }; setEncoding() {} @@ -798,11 +800,17 @@ export async function renderHook( let waitUntilReady: () => Promise = async () => {}; let generateSvg: () => string = () => ''; - const renderResult = await render( - - - , - ); + let renderResult!: Omit< + RenderInstance, + 'capturedOverflowState' | 'capturedOverflowActions' + >; + await act(async () => { + renderResult = await render( + + + , + ); + }); inkRerender = renderResult.rerender; unmount = renderResult.unmount; waitUntilReady = renderResult.waitUntilReady; diff --git a/packages/cli/src/ui/hooks/useShellHistory.test.ts b/packages/cli/src/ui/hooks/useShellHistory.test.ts index 2ed8608141..71dfe5e1ff 100644 --- a/packages/cli/src/ui/hooks/useShellHistory.test.ts +++ b/packages/cli/src/ui/hooks/useShellHistory.test.ts @@ -100,9 +100,10 @@ describe('useShellHistory', () => { it('should initialize and read the history file from the correct path', async () => { mockedFs.readFile.mockResolvedValue('cmd1\ncmd2'); - const { result, unmount } = await renderHook(() => + const { result, unmount, waitUntilReady } = await renderHook(() => useShellHistory(MOCKED_PROJECT_ROOT), ); + await waitUntilReady(); await waitFor(() => { expect(mockedFs.readFile).toHaveBeenCalledWith( @@ -127,9 +128,10 @@ describe('useShellHistory', () => { error.code = 'ENOENT'; mockedFs.readFile.mockRejectedValue(error); - const { result, unmount } = await renderHook(() => + const { result, unmount, waitUntilReady } = await renderHook(() => useShellHistory(MOCKED_PROJECT_ROOT), ); + await waitUntilReady(); await waitFor(() => { expect(mockedFs.readFile).toHaveBeenCalled(); @@ -146,9 +148,10 @@ describe('useShellHistory', () => { }); it('should add a command and write to the history file', async () => { - const { result, unmount } = await renderHook(() => + const { result, unmount, waitUntilReady } = await renderHook(() => useShellHistory(MOCKED_PROJECT_ROOT), ); + await waitUntilReady(); await waitFor(() => { expect(mockedFs.readFile).toHaveBeenCalled(); @@ -179,9 +182,10 @@ describe('useShellHistory', () => { it('should navigate history correctly with previous/next commands', async () => { mockedFs.readFile.mockResolvedValue('cmd1\ncmd2\ncmd3'); - const { result, unmount } = await renderHook(() => + const { result, unmount, waitUntilReady } = await renderHook(() => useShellHistory(MOCKED_PROJECT_ROOT), ); + await waitUntilReady(); // Wait for history to be loaded: ['cmd3', 'cmd2', 'cmd1'] await waitFor(() => { @@ -231,9 +235,10 @@ describe('useShellHistory', () => { }); it('should not add empty or whitespace-only commands to history', async () => { - const { result, unmount } = await renderHook(() => + const { result, unmount, waitUntilReady } = await renderHook(() => useShellHistory(MOCKED_PROJECT_ROOT), ); + await waitUntilReady(); await waitFor(() => { expect(mockedFs.readFile).toHaveBeenCalled(); @@ -252,9 +257,11 @@ describe('useShellHistory', () => { const oldCommands = Array.from({ length: 120 }, (_, i) => `old_cmd_${i}`); mockedFs.readFile.mockResolvedValue(oldCommands.join('\n')); - const { result, unmount } = await renderHook(() => + const { result, unmount, waitUntilReady } = await renderHook(() => useShellHistory(MOCKED_PROJECT_ROOT), ); + await waitUntilReady(); + await waitFor(() => { expect(mockedFs.readFile).toHaveBeenCalled(); }); @@ -284,9 +291,10 @@ describe('useShellHistory', () => { it('should move an existing command to the top when re-added', async () => { mockedFs.readFile.mockResolvedValue('cmd1\ncmd2\ncmd3'); - const { result, unmount } = await renderHook(() => + const { result, unmount, waitUntilReady } = await renderHook(() => useShellHistory(MOCKED_PROJECT_ROOT), ); + await waitUntilReady(); // Initial state: ['cmd3', 'cmd2', 'cmd1'] await waitFor(() => {