Migrate core render util to use xterm.js as part of the rendering loop. (#19044)

This commit is contained in:
Jacob Richman
2026-02-18 16:46:50 -08:00
committed by GitHub
parent 04c52513e7
commit 04f65f3d55
213 changed files with 7065 additions and 3852 deletions

View File

@@ -25,16 +25,20 @@ const mockStdin = new EventEmitter() as unknown as NodeJS.ReadStream &
},
);
vi.mock('ink', () => ({
useStdin: () => ({
stdin: mockStdin,
}),
useStdout: () => ({
stdout: {
write: vi.fn(),
},
}),
}));
vi.mock('ink', async (importOriginal) => {
const actual = await importOriginal<typeof import('ink')>();
return {
...actual,
useStdin: () => ({
stdin: mockStdin,
}),
useStdout: () => ({
stdout: {
write: vi.fn(),
},
}),
};
});
const TestComponent = ({ onColor }: { onColor: (c: string) => void }) => {
const { subscribe } = useTerminalContext();
@@ -47,40 +51,47 @@ const TestComponent = ({ onColor }: { onColor: (c: string) => void }) => {
describe('TerminalContext', () => {
it('should parse OSC 11 response', async () => {
const handleColor = vi.fn();
render(
const { waitUntilReady, unmount } = render(
<TerminalProvider>
<TestComponent onColor={handleColor} />
</TerminalProvider>,
);
await waitUntilReady();
act(() => {
await act(async () => {
mockStdin.emit('data', '\x1b]11;rgb:ffff/ffff/ffff\x1b\\');
});
await waitUntilReady();
await waitFor(() => {
expect(handleColor).toHaveBeenCalledWith('rgb:ffff/ffff/ffff');
});
unmount();
});
it('should handle partial chunks', async () => {
const handleColor = vi.fn();
render(
const { waitUntilReady, unmount } = render(
<TerminalProvider>
<TestComponent onColor={handleColor} />
</TerminalProvider>,
);
await waitUntilReady();
act(() => {
await act(async () => {
mockStdin.emit('data', '\x1b]11;rgb:0000/');
});
await waitUntilReady();
expect(handleColor).not.toHaveBeenCalled();
act(() => {
await act(async () => {
mockStdin.emit('data', '0000/0000\x1b\\');
});
await waitUntilReady();
await waitFor(() => {
expect(handleColor).toHaveBeenCalledWith('rgb:0000/0000/0000');
});
unmount();
});
});