feat(testing): add raw frame access via lastFrame({ raw: true })

Stores raw (untrimmed) frames internally. lastFrame() still trims
by default for backward compat. lastFrame({ raw: true }) returns
the untrimmed output for layout tests asserting exact widths.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Yunfei He
2026-05-25 20:37:01 +08:00
parent ff75506371
commit 5a3de85079
+7 -3
View File
@@ -19,7 +19,7 @@ export interface Terminal {
}
export interface RenderResult {
lastFrame(this: void): string | undefined;
lastFrame(this: void, opts?: { raw?: boolean }): string | undefined;
frames: string[];
stdin: {
write(data: string): Promise<void>;
@@ -53,7 +53,7 @@ export async function render(
const frames: string[] = [];
stdout.on("data", (chunk) => {
frames.push(trimFrame(chunk.toString()));
frames.push(chunk.toString());
});
const app: TuiApp = createApp(component, options.props ?? undefined);
@@ -82,7 +82,11 @@ export async function render(
};
return {
lastFrame: () => frames.at(-1),
lastFrame: (opts?: { raw?: boolean }) => {
const f = frames.at(-1);
if (!f) return undefined;
return opts?.raw ? f : trimFrame(f);
},
frames,
stdin: {
async write(data: string): Promise<void> {