Files
vue-tui/packages/runtime-tests/integration/composables/use-stdout.test.tsx
T
Yunfei He a280b4f684 feat: add interactive mode detection and output stream coordination
- Auto-detect interactive mode via is-in-ci + stdout.isTTY
- writeToStdout/writeToStderr with frame clear/restore coordination
- Non-interactive mode: static immediate, dynamic at unmount
- Cursor position tracking for Phase 5 useCursor integration
- useStdout/useStderr route through coordinated context methods

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 15:34:41 +08:00

45 lines
1.5 KiB
TypeScript

import { defineComponent, onMounted } from "vue";
import { expect, test } from "vite-plus/test";
import { render } from "@vue-tui/testing";
import { Text, useStdout } from "@vue-tui/runtime";
test("useStdout.write does not corrupt active frame in debug mode", async () => {
const App = defineComponent(() => {
const { write } = useStdout();
onMounted(() => write("log line\n"));
return () => <Text>UI</Text>;
});
const { lastFrame } = await render(App);
expect(lastFrame()).toContain("UI");
});
test("useStdout returns stdout stream from context", async () => {
let stdoutRef: NodeJS.WriteStream | undefined;
const App = defineComponent(() => {
const { stdout } = useStdout();
stdoutRef = stdout;
return () => <Text>hello</Text>;
});
await render(App);
expect(stdoutRef).toBeDefined();
});
test("useStdout.write routes through writeToStdout", async () => {
const writes: string[] = [];
const App = defineComponent(() => {
const { write, stdout } = useStdout();
// Capture all writes to the stdout stream
const origWrite = stdout.write.bind(stdout);
stdout.write = ((data: string) => {
writes.push(data);
return origWrite(data);
}) as typeof stdout.write;
onMounted(() => write("test-data"));
return () => <Text>frame</Text>;
});
const { lastFrame } = await render(App);
// The write should have gone through, and the frame should still be intact
expect(lastFrame()).toContain("frame");
expect(writes.some((w) => w.includes("test-data"))).toBe(true);
});