Files
codex/codex-cli/tests/ui-test-helpers.js
Eason Goodale 35148c2ba9 tests pass
2025-04-19 18:49:29 -07:00

29 lines
787 B
JavaScript
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 React from "react";
import { render } from "ink-testing-library";
import stripAnsi from "strip-ansi";
export function renderTui(ui) {
const { stdin, lastFrame, unmount, cleanup } = render(ui, {
exitOnCtrlC: false,
});
// Some libraries assume these methods exist on TTY streams; add noops.
if (stdin && typeof stdin.ref !== "function") {
// @ts-ignore
stdin.ref = () => {};
}
if (stdin && typeof stdin.unref !== "function") {
// @ts-ignore
stdin.unref = () => {};
}
const lastFrameStripped = () => stripAnsi(lastFrame() ?? "");
async function flush() {
// wait one tick for Ink to process
await new Promise((resolve) => setTimeout(resolve, 0));
}
return { stdin, lastFrame, lastFrameStripped, unmount, cleanup, flush };
}