Files
vue-tui/packages/testing
Yunfei He 3ee01dc278 feat: add patchConsole, waitUntilRenderFlush, onRender, and maxFps
Add four behavioral surfaces to the runtime:

- patchConsole (default: true): intercepts console.* methods to route
  output through writeToStdout/writeToStderr, preventing frame corruption.
  Disabled in debug mode. Restored before Vue cleanup on teardown.
- waitUntilRenderFlush(): flushes pending throttled renders and waits
  for the stdout write barrier, exposed on TuiApp and testing RenderResult.
- onRender callback: fires after each commit with { renderTime } in ms.
- maxFps option: overrides the scheduler's default 32ms throttle interval
  with 1000/maxFps. The scheduler now accepts a throttleMs option and
  exposes hasPending() for flush coordination.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 15:54:18 +08:00
..
2026-05-24 22:58:29 +08:00
2026-05-24 22:58:29 +08:00

@vue-tui/testing

Test harness for @vue-tui/runtime.

Install

pnpm add -D @vue-tui/testing vue

Quickstart

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 (use .waitUntilExit() if needed).
  • result.unmount() / result.waitUntilExit() — convenience pass-throughs.