Files
vue-tui/packages/runtime-tests/integration/pty/helpers/run.ts
T
Yunfei He 8befc0d0de fix: rewrite PTY tests to use node-pty directly, upgrade to 1.2.0-beta.13
node-pty 1.1.0's POSIX_SPAWN_CLOEXEC_DEFAULT flag fails on macOS 26 (Tahoe).
Beta.13 fixes this. Rewrote helpers to match Ink's node-pty architecture,
removed python pty-spawn and force-tty workarounds, added check-pty guard
that skips all 82 tests when node-pty is unavailable.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-27 01:08:25 +08:00

51 lines
1.3 KiB
TypeScript

import process from "node:process";
import { createRequire } from "node:module";
import path from "node:path";
import url from "node:url";
const require = createRequire(import.meta.url);
const { spawn } = require("node-pty") as typeof import("node-pty");
const fixturesDir = url.fileURLToPath(new URL("../fixtures", import.meta.url));
type RunProps = { env?: Record<string, string>; columns?: number };
export const run = async (fixture: string, props?: RunProps): Promise<string> => {
const env: Record<string, string> = {
...(process.env as Record<string, string>),
CI: "false",
NODE_NO_WARNINGS: "1",
FORCE_COLOR: "3",
...props?.env,
};
if (props?.columns !== undefined) {
env["COLUMNS"] = String(props.columns);
}
return new Promise<string>((resolve, reject) => {
const term = spawn("node", ["--import=tsx", path.join(fixturesDir, `${fixture}.tsx`)], {
name: "xterm-color",
cols: typeof props?.columns === "number" ? props.columns : 100,
cwd: fixturesDir,
env,
});
let output = "";
term.onData((data) => {
output += data;
});
term.onExit(({ exitCode }) => {
if (exitCode === 0) {
resolve(output);
return;
}
reject(new Error(`Process exited with non-zero code: ${exitCode}\n${output}`));
});
});
};