import { describe, expect, it } from "vitest"; import { execFileOutput } from "./ExecFileOutput.js"; describe("execFileOutput", () => { it("captures output larger than Node's default execFile limit", async () => { const marker = "tail-marker"; const result = await execFileOutput(process.execPath, [ "-e", `process.stdout.write("x".repeat(2 * 1024 * 1024)); process.stdout.write(${JSON.stringify(marker)});`, ]); expect(result.stdout).toHaveLength(2 * 1024 * 1024 + marker.length); expect(result.stdout.endsWith(marker)).toBe(true); }); it("enforces a caller supplied output bound", async () => { await expect( execFileOutput( process.execPath, ["-e", 'process.stdout.write("x".repeat(1024))'], { maxBuffer: 64 }, ), ).rejects.toMatchObject({ code: "ERR_CHILD_PROCESS_STDIO_MAXBUFFER" }); }); it("retains both captured streams on a failed child process", async () => { await expect( execFileOutput(process.execPath, [ "-e", 'process.stdout.write("out"); process.stderr.write("err"); process.exitCode = 7;', ]), ).rejects.toMatchObject({ code: 7, stdout: "out", stderr: "err" }); }); });