feat(testing): test harness for @vue-tui/runtime

Provides render() for integration testing — async with auto-flush,
trimmed frames, fake terminal with resize(), stdin.write() with
auto-flush, and auto-cleanup via afterEach.

Exports: render, cleanup, RenderResult, RenderOptions, Terminal

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Yunfei He
2026-05-24 18:13:47 +08:00
parent ff82f6e064
commit 71c517b79f
10 changed files with 327 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
# @vue-tui/testing
Test harness for [`@vue-tui/runtime`](../runtime).
## Install
```bash
pnpm add -D @vue-tui/testing vue
```
## Quickstart
```ts
import { defineComponent, h } from "vue";
import { test, expect } from "vitest";
import { render, flush } from "@vue-tui/testing";
import { Text } from "@vue-tui/runtime";
test("renders hello", async () => {
const App = defineComponent({ render: () => h(Text, null, "hello") });
const r = render(App);
await flush();
expect(r.lastFrame()).toContain("hello");
r.unmount();
});
```
## API
- **`render(app, { columns?, rows? })`** — mount in a fake-TTY environment, collect frames.
- **`flush()`** — await Vue's post-flush queue + Node's immediate queue.
- **`result.lastFrame()` / `result.frames`** — frame snapshots.
- **`result.stdin.write(data)`** — inject input that reaches `useInput` handlers.
- **`result.app`** — the underlying [`TuiApp`](../runtime/README.md#tuiapp-interface) (use `.waitUntilExit()` if needed).
- **`result.unmount()` / `result.waitUntilExit()`** — convenience pass-throughs.