|
| 1 | +// Tests for exec output rendering helpers. |
| 2 | +import { describe, expect, it } from "vitest"; |
| 3 | +import { renderExecOutputText, renderExecUpdateText } from "./bash-tools.exec-output.js"; |
| 4 | + |
| 5 | +describe("renderExecOutputText", () => { |
| 6 | + it("returns placeholder for undefined input", () => { |
| 7 | + expect(renderExecOutputText(undefined)).toBe("(no output)"); |
| 8 | + }); |
| 9 | + |
| 10 | + it("returns placeholder for empty string", () => { |
| 11 | + expect(renderExecOutputText("")).toBe("(no output)"); |
| 12 | + }); |
| 13 | + |
| 14 | + it("returns value for non-empty string", () => { |
| 15 | + expect(renderExecOutputText("hello")).toBe("hello"); |
| 16 | + }); |
| 17 | + |
| 18 | + it("returns value for whitespace-only string", () => { |
| 19 | + expect(renderExecOutputText(" ")).toBe(" "); |
| 20 | + }); |
| 21 | + |
| 22 | + it("preserves newlines in output", () => { |
| 23 | + expect(renderExecOutputText("line1\nline2")).toBe("line1\nline2"); |
| 24 | + }); |
| 25 | +}); |
| 26 | + |
| 27 | +describe("renderExecUpdateText", () => { |
| 28 | + it("returns placeholder when no tailText and no warnings", () => { |
| 29 | + expect(renderExecUpdateText({ warnings: [] })).toBe("(no output)"); |
| 30 | + }); |
| 31 | + |
| 32 | + it("returns tailText when no warnings", () => { |
| 33 | + expect(renderExecUpdateText({ tailText: "hello", warnings: [] })).toBe("hello"); |
| 34 | + }); |
| 35 | + |
| 36 | + it("returns warnings when no tailText", () => { |
| 37 | + expect(renderExecUpdateText({ warnings: ["warning1"] })).toBe("warning1\n\n(no output)"); |
| 38 | + }); |
| 39 | + |
| 40 | + it("returns warnings followed by tailText", () => { |
| 41 | + expect(renderExecUpdateText({ tailText: "hello", warnings: ["warning1"] })).toBe( |
| 42 | + "warning1\n\nhello", |
| 43 | + ); |
| 44 | + }); |
| 45 | + |
| 46 | + it("joins multiple warnings with newlines", () => { |
| 47 | + expect(renderExecUpdateText({ tailText: "hello", warnings: ["warning1", "warning2"] })).toBe( |
| 48 | + "warning1\nwarning2\n\nhello", |
| 49 | + ); |
| 50 | + }); |
| 51 | + |
| 52 | + it("handles empty warnings array with tailText", () => { |
| 53 | + expect(renderExecUpdateText({ tailText: "hello", warnings: [] })).toBe("hello"); |
| 54 | + }); |
| 55 | + |
| 56 | + it("handles undefined tailText with warnings", () => { |
| 57 | + expect(renderExecUpdateText({ warnings: ["warning1"] })).toBe("warning1\n\n(no output)"); |
| 58 | + }); |
| 59 | +}); |
0 commit comments