41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { stripAnsi } from "./ansi";
|
|
|
|
describe("stripAnsi", () => {
|
|
it("returns input unchanged when there are no escape sequences", () => {
|
|
expect(stripAnsi("hello world")).toBe("hello world");
|
|
});
|
|
|
|
it("strips SGR colour codes", () => {
|
|
const input = "\x1b[36mInstalling backend dependencies...\x1b[0m";
|
|
expect(stripAnsi(input)).toBe("Installing backend dependencies...");
|
|
});
|
|
|
|
it("strips bold + colour wrapped output across multiple lines", () => {
|
|
const input =
|
|
"\x1b[36mInstalling deps...\x1b[0m\nDownloading...\n\x1b[32m\x1b[1m✓ All dependencies installed!\x1b[0m";
|
|
expect(stripAnsi(input)).toBe(
|
|
"Installing deps...\nDownloading...\n✓ All dependencies installed!",
|
|
);
|
|
});
|
|
|
|
it("handles empty string", () => {
|
|
expect(stripAnsi("")).toBe("");
|
|
});
|
|
|
|
it("strips OSC hyperlinks terminated by ST", () => {
|
|
const input = "click \x1b]8;;https://example.com\x1b\\here\x1b]8;;\x1b\\!";
|
|
expect(stripAnsi(input)).toBe("click here!");
|
|
});
|
|
|
|
it("strips OSC window-title sequences terminated by BEL", () => {
|
|
const input = "\x1b]0;my-shell\x07ready";
|
|
expect(stripAnsi(input)).toBe("ready");
|
|
});
|
|
|
|
it("strips CSI private-prefix sequences (hide cursor, bracketed paste)", () => {
|
|
expect(stripAnsi("before\x1b[?25lafter")).toBe("beforeafter");
|
|
expect(stripAnsi("\x1b[?2004hpaste\x1b[?2004l")).toBe("paste");
|
|
});
|
|
});
|