refactor(test): dedupe terminal restore stubs

This commit is contained in:
Peter Steinberger
2026-02-15 21:55:56 +00:00
parent 8cd20e220f
commit 511719424d

View File

@@ -8,6 +8,20 @@ vi.mock("./progress-line.js", () => ({
import { restoreTerminalState } from "./restore.js";
function configureTerminalIO(params: {
stdinIsTTY: boolean;
stdoutIsTTY: boolean;
setRawMode?: (mode: boolean) => void;
resume?: () => void;
isPaused?: () => boolean;
}) {
Object.defineProperty(process.stdin, "isTTY", { value: params.stdinIsTTY, configurable: true });
Object.defineProperty(process.stdout, "isTTY", { value: params.stdoutIsTTY, configurable: true });
(process.stdin as { setRawMode?: (mode: boolean) => void }).setRawMode = params.setRawMode;
(process.stdin as { resume?: () => void }).resume = params.resume;
(process.stdin as { isPaused?: () => boolean }).isPaused = params.isPaused;
}
describe("restoreTerminalState", () => {
const originalStdinIsTTY = process.stdin.isTTY;
const originalStdoutIsTTY = process.stdout.isTTY;
@@ -35,11 +49,13 @@ describe("restoreTerminalState", () => {
const resume = vi.fn();
const isPaused = vi.fn(() => true);
Object.defineProperty(process.stdin, "isTTY", { value: true, configurable: true });
Object.defineProperty(process.stdout, "isTTY", { value: false, configurable: true });
(process.stdin as { setRawMode?: (mode: boolean) => void }).setRawMode = setRawMode;
(process.stdin as { resume?: () => void }).resume = resume;
(process.stdin as { isPaused?: () => boolean }).isPaused = isPaused;
configureTerminalIO({
stdinIsTTY: true,
stdoutIsTTY: false,
setRawMode,
resume,
isPaused,
});
restoreTerminalState("test");
@@ -52,11 +68,13 @@ describe("restoreTerminalState", () => {
const resume = vi.fn();
const isPaused = vi.fn(() => true);
Object.defineProperty(process.stdin, "isTTY", { value: true, configurable: true });
Object.defineProperty(process.stdout, "isTTY", { value: false, configurable: true });
(process.stdin as { setRawMode?: (mode: boolean) => void }).setRawMode = setRawMode;
(process.stdin as { resume?: () => void }).resume = resume;
(process.stdin as { isPaused?: () => boolean }).isPaused = isPaused;
configureTerminalIO({
stdinIsTTY: true,
stdoutIsTTY: false,
setRawMode,
resume,
isPaused,
});
restoreTerminalState("test", { resumeStdinIfPaused: true });
@@ -69,11 +87,13 @@ describe("restoreTerminalState", () => {
const resume = vi.fn();
const isPaused = vi.fn(() => true);
Object.defineProperty(process.stdin, "isTTY", { value: false, configurable: true });
Object.defineProperty(process.stdout, "isTTY", { value: false, configurable: true });
(process.stdin as { setRawMode?: (mode: boolean) => void }).setRawMode = setRawMode;
(process.stdin as { resume?: () => void }).resume = resume;
(process.stdin as { isPaused?: () => boolean }).isPaused = isPaused;
configureTerminalIO({
stdinIsTTY: false,
stdoutIsTTY: false,
setRawMode,
resume,
isPaused,
});
restoreTerminalState("test", { resumeStdinIfPaused: true });