


























@@ -1,5 +1,22 @@
11import { describe, expect, it, vi } from "vitest";
2-import { createCliProgress } from "./progress.js";
2+import { createCliProgress, shouldUseInteractiveProgressSpinner } from "./progress.js";
3+4+function withStdinIsRaw<T>(isRaw: boolean, run: () => T): T {
5+const original = Object.getOwnPropertyDescriptor(process.stdin, "isRaw");
6+Object.defineProperty(process.stdin, "isRaw", {
7+configurable: true,
8+value: isRaw,
9+});
10+try {
11+return run();
12+} finally {
13+if (original) {
14+Object.defineProperty(process.stdin, "isRaw", original);
15+} else {
16+Reflect.deleteProperty(process.stdin, "isRaw");
17+}
18+}
19+}
320421describe("cli progress", () => {
522it("logs progress when non-tty and fallback=log", () => {
@@ -43,4 +60,45 @@ describe("cli progress", () => {
43604461expect(write).not.toHaveBeenCalled();
4562});
63+64+it("does not use readline-backed spinners while raw TUI input is active", () => {
65+expect(
66+shouldUseInteractiveProgressSpinner({
67+streamIsTty: true,
68+stdinIsRaw: true,
69+}),
70+).toBe(false);
71+});
72+73+it("keeps the normal interactive spinner for regular tty commands", () => {
74+expect(
75+shouldUseInteractiveProgressSpinner({
76+streamIsTty: true,
77+stdinIsRaw: false,
78+}),
79+).toBe(true);
80+});
81+82+it("does not write terminal controls when raw TUI input suppresses the default spinner", () => {
83+const writes: string[] = [];
84+const stream = {
85+isTTY: true,
86+write: vi.fn((chunk: string) => {
87+writes.push(chunk);
88+}),
89+} as unknown as NodeJS.WriteStream;
90+91+withStdinIsRaw(true, () => {
92+const progress = createCliProgress({
93+label: "Scanning",
94+total: 2,
95+ stream,
96+});
97+progress.setLabel("Still scanning");
98+progress.tick();
99+progress.done();
100+});
101+102+expect(writes).toEqual([]);
103+});
46104});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。