test: add PTY console and useStdout fixture scripts + tests

Port console.log and useStdout.write fixtures from Ink to verify
patchConsole and useStdout().write() work correctly in a real terminal.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Yunfei He
2026-05-26 22:45:17 +08:00
parent 15aca4502d
commit 3995e84285
3 changed files with 53 additions and 0 deletions
@@ -0,0 +1,14 @@
import { test, expect } from "vite-plus/test";
import { run } from "./helpers/run.ts";
test.sequential("console.log doesn't corrupt output", async () => {
const output = await run("console");
expect(output).toContain("First log");
expect(output).toContain("Second log");
});
test.sequential("useStdout.write in real terminal", async () => {
const output = await run("use-stdout");
expect(output).toContain("Hello from vue-tui to stdout");
expect(output).toContain("exited");
});
@@ -0,0 +1,20 @@
import { createApp, Text } from "@vue-tui/runtime";
import { defineComponent, h, onMounted, onScopeDispose } from "vue";
const App = defineComponent(() => {
onMounted(() => {
const timer = setTimeout(() => {}, 1000);
onScopeDispose(() => {
clearTimeout(timer);
});
});
return () => h(Text, null, { default: () => "Hello World" });
});
const app = createApp(App);
app.mount();
console.log("First log");
app.unmount();
console.log("Second log");
@@ -0,0 +1,19 @@
import { createApp, Text, useStdout, useExit } from "@vue-tui/runtime";
import { defineComponent, h, onMounted } from "vue";
const WriteToStdout = defineComponent(() => {
const { write } = useStdout();
const exit = useExit();
onMounted(() => {
write("Hello from vue-tui to stdout\n");
exit();
});
return () => h(Text, null, { default: () => "Hello World" });
});
const app = createApp(WriteToStdout);
app.mount();
await app.waitUntilExit();
console.log("exited");