Files
llmx/codex-cli/tests/ui-test-helpers.tsx
Ilan Bigio 59a180ddec Initial commit
Signed-off-by: Ilan Bigio <ilan@openai.com>
2025-04-16 12:56:08 -04:00

29 lines
814 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type React from "react";
import { render } from "ink-testing-library";
import stripAnsi from "strip-ansi";
/**
* Render an Ink component for testing.
*
* Returns the full testinglibrary utils plus `lastFrameStripped()` which
* yields the latest rendered frame with ANSI escape codes removed so that
* assertions can be colouragnostic.
*/
export function renderTui(ui: React.ReactElement): any {
const utils = render(ui);
const lastFrameStripped = () => stripAnsi(utils.lastFrame() || "");
// A tiny helper that waits for Ink's internal promises / timers to settle
// so the next `lastFrame()` call reflects the latest UI state.
const flush = async () =>
new Promise<void>((resolve) => setTimeout(resolve, 0));
return {
...utils,
lastFrameStripped,
flush,
};
}