Fix wrap-ansi test to use node:test instead of vitest

This commit is contained in:
Mario Zechner 2025-12-06 00:48:46 +01:00
parent 4a972fbe6c
commit ee83284dcf
2 changed files with 58 additions and 62 deletions

View file

@ -1,4 +1,5 @@
import { describe, expect, it } from "vitest";
import assert from "node:assert";
import { describe, it } from "node:test";
import { visibleWidth, wrapTextWithAnsi } from "../src/utils.js";
describe("wrapTextWithAnsi", () => {
@ -12,11 +13,11 @@ describe("wrapTextWithAnsi", () => {
const wrapped = wrapTextWithAnsi(text, 40);
// First line should NOT contain underline code - it's just "read this thread "
expect(wrapped[0]).toBe("read this thread ");
assert.strictEqual(wrapped[0], "read this thread ");
// Second line should start with underline, have URL content
expect(wrapped[1].startsWith(underlineOn)).toBe(true);
expect(wrapped[1]).toContain("https://");
assert.strictEqual(wrapped[1].startsWith(underlineOn), true);
assert.ok(wrapped[1].includes("https://"));
});
it("should not bleed underline to padding - each line should end with reset for underline only", () => {
@ -33,8 +34,8 @@ describe("wrapTextWithAnsi", () => {
const line = wrapped[i];
if (line.includes(underlineOn)) {
// Should end with underline off, NOT full reset
expect(line.endsWith(underlineOff)).toBe(true);
expect(line.endsWith("\x1b[0m")).toBe(false);
assert.strictEqual(line.endsWith(underlineOff), true);
assert.strictEqual(line.endsWith("\x1b[0m"), false);
}
}
});
@ -50,12 +51,12 @@ describe("wrapTextWithAnsi", () => {
// Each line should have background color
for (const line of wrapped) {
expect(line.includes(bgBlue)).toBe(true);
assert.ok(line.includes(bgBlue));
}
// Middle lines should NOT end with full reset (kills background for padding)
for (let i = 0; i < wrapped.length - 1; i++) {
expect(wrapped[i].endsWith("\x1b[0m")).toBe(false);
assert.strictEqual(wrapped[i].endsWith("\x1b[0m"), false);
}
});
@ -68,15 +69,10 @@ describe("wrapTextWithAnsi", () => {
const wrapped = wrapTextWithAnsi(text, 20);
console.log("Wrapped lines:");
for (let i = 0; i < wrapped.length; i++) {
console.log(` [${i}]: ${JSON.stringify(wrapped[i])}`);
}
// All lines should have background color 41 (either as \x1b[41m or combined like \x1b[4;41m)
for (const line of wrapped) {
const hasBgColor = line.includes("[41m") || line.includes(";41m") || line.includes("[41;");
expect(hasBgColor).toBe(true);
assert.ok(hasBgColor);
}
// Lines with underlined content should use underline-off at end, not full reset
@ -87,8 +83,8 @@ describe("wrapTextWithAnsi", () => {
(line.includes("[4m") || line.includes("[4;") || line.includes(";4m")) &&
!line.includes(underlineOff)
) {
expect(line.endsWith(underlineOff)).toBe(true);
expect(line.endsWith("\x1b[0m")).toBe(false);
assert.strictEqual(line.endsWith(underlineOff), true);
assert.strictEqual(line.endsWith("\x1b[0m"), false);
}
}
});
@ -99,10 +95,10 @@ describe("wrapTextWithAnsi", () => {
const text = "hello world this is a test";
const wrapped = wrapTextWithAnsi(text, 10);
expect(wrapped.length).toBeGreaterThan(1);
wrapped.forEach((line) => {
expect(visibleWidth(line)).toBeLessThanOrEqual(10);
});
assert.ok(wrapped.length > 1);
for (const line of wrapped) {
assert.ok(visibleWidth(line) <= 10);
}
});
it("should preserve color codes across wraps", () => {
@ -114,12 +110,12 @@ describe("wrapTextWithAnsi", () => {
// Each continuation line should start with red code
for (let i = 1; i < wrapped.length; i++) {
expect(wrapped[i].startsWith(red)).toBe(true);
assert.strictEqual(wrapped[i].startsWith(red), true);
}
// Middle lines should not end with full reset
for (let i = 0; i < wrapped.length - 1; i++) {
expect(wrapped[i].endsWith("\x1b[0m")).toBe(false);
assert.strictEqual(wrapped[i].endsWith("\x1b[0m"), false);
}
});
});