# 🚀 Sync Gemini CLI v0.2.1 - Major Feature Update (#483)
Some checks are pending
Qwen Code CI / Lint (GitHub Actions) (push) Waiting to run
Qwen Code CI / Lint (Javascript) (push) Waiting to run
Qwen Code CI / Lint (Shell) (push) Waiting to run
Qwen Code CI / Lint (YAML) (push) Waiting to run
Qwen Code CI / Lint (push) Blocked by required conditions
Qwen Code CI / Test (push) Blocked by required conditions
Qwen Code CI / Post Coverage Comment (push) Blocked by required conditions
Qwen Code CI / CodeQL (push) Waiting to run
E2E Tests / E2E Test (Linux) - sandbox:docker (push) Waiting to run
E2E Tests / E2E Test (Linux) - sandbox:none (push) Waiting to run
E2E Tests / E2E Test - macOS (push) Waiting to run

This commit is contained in:
tanzhenxin 2025-09-01 14:48:55 +08:00 committed by GitHub
parent 1610c1586e
commit 2572faf726
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
292 changed files with 19401 additions and 5941 deletions

View file

@ -4,8 +4,10 @@
* SPDX-License-Identifier: Apache-2.0
*/
import React from 'react';
import { renderHook, act } from '@testing-library/react';
import { useKeypress, Key } from './useKeypress.js';
import { KeypressProvider } from '../contexts/KeypressContext.js';
import { useStdin } from 'ink';
import { EventEmitter } from 'events';
import { PassThrough } from 'stream';
@ -102,6 +104,9 @@ describe('useKeypress', () => {
const onKeypress = vi.fn();
let originalNodeVersion: string;
const wrapper = ({ children }: { children: React.ReactNode }) =>
React.createElement(KeypressProvider, null, children);
beforeEach(() => {
vi.clearAllMocks();
stdin = new MockStdin();
@ -111,7 +116,7 @@ describe('useKeypress', () => {
});
originalNodeVersion = process.versions.node;
delete process.env['PASTE_WORKAROUND'];
vi.unstubAllEnvs();
});
afterEach(() => {
@ -129,7 +134,9 @@ describe('useKeypress', () => {
};
it('should not listen if isActive is false', () => {
renderHook(() => useKeypress(onKeypress, { isActive: false }));
renderHook(() => useKeypress(onKeypress, { isActive: false }), {
wrapper,
});
act(() => stdin.pressKey({ name: 'a' }));
expect(onKeypress).not.toHaveBeenCalled();
});
@ -141,14 +148,15 @@ describe('useKeypress', () => {
{ key: { name: 'up', sequence: '\x1b[A' } },
{ key: { name: 'down', sequence: '\x1b[B' } },
])('should listen for keypress when active for key $key.name', ({ key }) => {
renderHook(() => useKeypress(onKeypress, { isActive: true }));
renderHook(() => useKeypress(onKeypress, { isActive: true }), { wrapper });
act(() => stdin.pressKey(key));
expect(onKeypress).toHaveBeenCalledWith(expect.objectContaining(key));
});
it('should set and release raw mode', () => {
const { unmount } = renderHook(() =>
useKeypress(onKeypress, { isActive: true }),
const { unmount } = renderHook(
() => useKeypress(onKeypress, { isActive: true }),
{ wrapper },
);
expect(mockSetRawMode).toHaveBeenCalledWith(true);
unmount();
@ -156,8 +164,9 @@ describe('useKeypress', () => {
});
it('should stop listening after being unmounted', () => {
const { unmount } = renderHook(() =>
useKeypress(onKeypress, { isActive: true }),
const { unmount } = renderHook(
() => useKeypress(onKeypress, { isActive: true }),
{ wrapper },
);
unmount();
act(() => stdin.pressKey({ name: 'a' }));
@ -165,7 +174,7 @@ describe('useKeypress', () => {
});
it('should correctly identify alt+enter (meta key)', () => {
renderHook(() => useKeypress(onKeypress, { isActive: true }));
renderHook(() => useKeypress(onKeypress, { isActive: true }), { wrapper });
const key = { name: 'return', sequence: '\x1B\r' };
act(() => stdin.pressKey(key));
expect(onKeypress).toHaveBeenCalledWith(
@ -188,7 +197,7 @@ describe('useKeypress', () => {
description: 'Workaround Env Var',
setup: () => {
setNodeVersion('20.0.0');
process.env['PASTE_WORKAROUND'] = 'true';
vi.stubEnv('PASTE_WORKAROUND', 'true');
},
isLegacy: true,
},
@ -199,7 +208,9 @@ describe('useKeypress', () => {
});
it('should process a paste as a single event', () => {
renderHook(() => useKeypress(onKeypress, { isActive: true }));
renderHook(() => useKeypress(onKeypress, { isActive: true }), {
wrapper,
});
const pasteText = 'hello world';
act(() => stdin.paste(pasteText));
@ -215,7 +226,9 @@ describe('useKeypress', () => {
});
it('should handle keypress interspersed with pastes', () => {
renderHook(() => useKeypress(onKeypress, { isActive: true }));
renderHook(() => useKeypress(onKeypress, { isActive: true }), {
wrapper,
});
const keyA = { name: 'a', sequence: 'a' };
act(() => stdin.pressKey(keyA));
@ -239,8 +252,9 @@ describe('useKeypress', () => {
});
it('should emit partial paste content if unmounted mid-paste', () => {
const { unmount } = renderHook(() =>
useKeypress(onKeypress, { isActive: true }),
const { unmount } = renderHook(
() => useKeypress(onKeypress, { isActive: true }),
{ wrapper },
);
const pasteText = 'incomplete paste';