mirror of
https://github.com/morluto/rea
synced 2026-10-27 06:33:32 -04:00
28 lines
675 B
TypeScript
28 lines
675 B
TypeScript
import { createCli } from "../../../src/cli.js";
|
|
|
|
/** Captured CLI invocation for boundary tests. */
|
|
export interface ServedCli {
|
|
readonly stdout: string;
|
|
readonly exitCode: number;
|
|
}
|
|
|
|
/** Serve one CLI invocation with captured output and exit code. */
|
|
export const serveCli = async (
|
|
argv: readonly string[],
|
|
environment: Readonly<Record<string, string | undefined>> = {},
|
|
): Promise<ServedCli> => {
|
|
const cli = createCli(environment);
|
|
let stdout = "";
|
|
let exitCode = 0;
|
|
await cli.serve([...argv], {
|
|
env: {},
|
|
exit: (code) => {
|
|
exitCode = code;
|
|
},
|
|
stdout: (text) => {
|
|
stdout += text;
|
|
},
|
|
});
|
|
return { stdout, exitCode };
|
|
};
|