Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions packages/cli-framework/src/output.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterEach, describe, expect, test } from "bun:test";
import { afterEach, beforeEach, describe, expect, test } from "bun:test";

import { formatOutput, table } from "./output";

Expand All @@ -14,14 +14,20 @@ const OSC8 = new RegExp(`${ESC}\\]8;;[^${BEL}]*${BEL}`, "g");

const originalIsTTY = process.stdout.isTTY;

const originalTerm = process.env.TERM;

function setTTY(value: boolean | undefined): void {
Object.defineProperty(process.stdout, "isTTY", {
value,
configurable: true,
});
}

afterEach(() => setTTY(originalIsTTY));
afterEach(() => {
setTTY(originalIsTTY);
if (originalTerm === undefined) delete process.env.TERM;
else process.env.TERM = originalTerm;
});

describe("formatOutput", () => {
const raw = { raw: "#!/bin/sh\necho hi\n" };
Expand Down Expand Up @@ -56,6 +62,18 @@ describe("formatOutput", () => {
});

describe("table", () => {
beforeEach(() => {
process.env.TERM = "xterm-256color";
});

test("prints a plain URL on a dumb terminal", () => {
setTTY(true);
process.env.TERM = "dumb";
const out = table(ROWS, COLUMNS, undefined, CAPS);
expect(out).toContain(URL);
expect(out).not.toContain("\x1b]8;;");
});

test("truncates a cell wider than its cap", () => {
setTTY(false);
const out = table(
Expand Down
Loading