fix(cli): stream non-TTY render progress (#2458)

This commit is contained in:
Miguel Ángel
2026-07-14 22:13:43 -04:00
committed by GitHub
parent d047d28bb4
commit cada0e7c09
2 changed files with 35 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
import { afterEach, describe, expect, it } from "vitest";
import { renderProgress } from "./progress.js";
const originalWrite = process.stdout.write.bind(process.stdout);
const originalIsTTY = process.stdout.isTTY;
afterEach(() => {
process.stdout.write = originalWrite;
Object.defineProperty(process.stdout, "isTTY", {
value: originalIsTTY,
configurable: true,
});
});
describe("renderProgress", () => {
it("emits line-delimited updates when stdout is not a TTY", () => {
let output = "";
Object.defineProperty(process.stdout, "isTTY", {
value: false,
configurable: true,
});
process.stdout.write = ((chunk: string | Uint8Array) => {
output += String(chunk);
return true;
}) as typeof process.stdout.write;
renderProgress(42, "Capturing frames");
expect(output).toMatch(/Capturing frames\n$/);
expect(output).not.toContain("\r");
});
});
+2
View File
@@ -12,6 +12,8 @@ export function renderProgress(percent: number, stage: string, row?: number): vo
if (row !== undefined && stdout.isTTY) {
stdout.write(`\x1b[${row};1H\x1b[2K${line}`);
} else if (!stdout.isTTY) {
stdout.write(`${line}\n`);
} else {
stdout.write(`\r\x1b[2K${line}`);
}