Files
vue-tui/packages/runtime-tests/integration/lifecycle/error-handling.sequential.test.tsx
T
Yunfei He 7d6a92ea15 test(runtime): lock render lifecycle, exit, error-handling, alt-screen, use-stdout (Ink parity) (#115)
Round-2 test-only locks (behaviors already at parity with Ink test/render.tsx,
exit.tsx, errors.tsx, hooks.tsx):
- resize re-render reflows content to the new width (exact narrowed round-border bytes)
  + consecutive width decreases each clear; onRender fires exactly once per rerender
  (tightened from `>`); onMounted runs before the first frame write callback (#596);
  bsu/esu wraps a trailing throttled content change, and an unchanged trailing rerender
  emits neither; patchConsole puts a log above the live frame.
- exit-with-static #397 non-duplication (A/B/C each render once) — the fixture is fixed
  to function slots so no [Vue warn] pollutes stdout; exit-with-thrown-error via run()'s
  strict exit-0 gate; DEV is inert; the process stays alive ~500ms while raw mode is held.
- raw mode is disabled on the thrown-error cleanup path; the unhandledRejection test moved
  to a *.sequential file (it mutates a process-global listener).
- alternate-screen enter sequence hides the cursor; useStdout().write() preserves the
  frame with the external write ordered above it.

Codex-reviewed GENUINE.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-01 03:07:35 +08:00

30 lines
1.2 KiB
TypeScript

// Sequential: this test installs a process-global `unhandledRejection` listener
// and asserts on what it captures. Under file-level parallelism a sibling test's
// stray rejection could be counted here (or ours leak there), so it must run
// isolated — mirroring Ink's test.serial for the same scenario. Moved out of the
// file-parallel error-handling.test.tsx per the repo's process-global convention.
import { defineComponent } from "vue";
import { expect, test } from "vite-plus/test";
import { render } from "@vue-tui/testing";
test.sequential("does not emit unhandledRejection when render exits with an error and waitUntilExit is unused", async () => {
const unhandledErrors: Error[] = [];
const handler = (reason: unknown) => {
unhandledErrors.push(reason as Error);
};
process.on("unhandledRejection", handler);
try {
const Boom = defineComponent(() => {
throw new Error("no-listener boom");
});
await render(Boom).catch(() => {});
// Give a tick for any stray rejections to surface
await new Promise((r) => setTimeout(r, 10));
expect(unhandledErrors).toHaveLength(0);
} finally {
process.off("unhandledRejection", handler);
}
});