From bde81cfdf1340e172765dd6e5d2107a876ec2474 Mon Sep 17 00:00:00 2001 From: Hardonian <118695431+Hardonian@users.noreply.github.com> Date: Fri, 29 May 2026 04:57:27 +0000 Subject: [PATCH] test: improve test coverage for stripAnsi --- src/lib/adapters/openshell/client.test.ts | 33 +++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/lib/adapters/openshell/client.test.ts b/src/lib/adapters/openshell/client.test.ts index bd3101e616..26ed372da1 100644 --- a/src/lib/adapters/openshell/client.test.ts +++ b/src/lib/adapters/openshell/client.test.ts @@ -49,8 +49,37 @@ function exitWithCode(code: number): never { } describe("openshell helpers", () => { - it("strips ANSI sequences", () => { - expect(stripAnsi("\u001b[32mConnected\u001b[0m")).toBe("Connected"); + describe("stripAnsi", () => { + it("strips basic color codes", () => { + expect(stripAnsi("\u001b[32mConnected\u001b[0m")).toBe("Connected"); + }); + + it("handles empty strings", () => { + expect(stripAnsi("")).toBe(""); + }); + + it("handles strings without ANSI codes", () => { + expect(stripAnsi("Plain text")).toBe("Plain text"); + }); + + it("handles complex ANSI sequences (e.g., bold, background, rgb)", () => { + // Bold red text on yellow background + expect(stripAnsi("\x1b[1;31;43mWarning\x1b[0m")).toBe("Warning"); + // RGB colors + expect(stripAnsi("\x1b[38;2;255;82;197mPink\x1b[0m")).toBe("Pink"); + // Complex multi-sequence text + expect(stripAnsi("\x1b[1mBold\x1b[0m and \x1b[4mUnderline\x1b[0m")).toBe("Bold and Underline"); + }); + + it("handles multiple ANSI sequences sequentially", () => { + expect(stripAnsi("\x1b[31m\x1b[1mRed Bold\x1b[0m\x1b[0m")).toBe("Red Bold"); + }); + + it("handles undefined gracefully by falling back to default parameter", () => { + expect(stripAnsi()).toBe(""); + expect(stripAnsi(undefined)).toBe(""); + }); + }); it("parses semantic versions from CLI output", () => {