diff --git a/packages/runtime-tests/integration/pty/console.test.ts b/packages/runtime-tests/integration/pty/console.test.ts new file mode 100644 index 0000000..fb4837d --- /dev/null +++ b/packages/runtime-tests/integration/pty/console.test.ts @@ -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"); +}); diff --git a/packages/runtime-tests/integration/pty/fixtures/console.tsx b/packages/runtime-tests/integration/pty/fixtures/console.tsx new file mode 100644 index 0000000..c6a5a11 --- /dev/null +++ b/packages/runtime-tests/integration/pty/fixtures/console.tsx @@ -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"); diff --git a/packages/runtime-tests/integration/pty/fixtures/use-stdout.tsx b/packages/runtime-tests/integration/pty/fixtures/use-stdout.tsx new file mode 100644 index 0000000..e446c9e --- /dev/null +++ b/packages/runtime-tests/integration/pty/fixtures/use-stdout.tsx @@ -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");