designpaca/packages/cli/test/units.test.ts
Yun Chan eecd3f03ff fix(core,cli): harden install engine and argument parsing
- Reject unknown flags with exit 2 and never write on --dry-run, even in a TTY
- Treat files already matching the new content as up to date after an interrupted update
- Remove unmodified orphan files from older versions, keep and report modified ones and shared paths
- Degrade malformed manifests instead of blocking installs; readIfExists only maps ENOENT/ENOTDIR to null
- Block downgrades from older CLIs (semver), honor uninstall --scope, dedupe targets, fix next-step output and table width
- Deeper package verification, LF normalization for .mjs, MIT LICENSE
2026-10-09 18:18:49 +09:00

48 lines
2.1 KiB
TypeScript

import assert from "node:assert/strict";
import { test } from "node:test";
import { compareVersions, isNewer } from "../src/semver.ts";
import { displayWidth, fold, heading, padDisplay, table } from "../src/ui.ts";
test("isNewer 는 숫자 세 칸을 semver 로 비교한다", () => {
assert.equal(isNewer("0.14.0", "0.12.0"), true);
assert.equal(isNewer("0.12.0", "0.14.0"), false);
assert.equal(isNewer("0.14.0", "0.14.0"), false);
assert.equal(isNewer("0.10.0", "0.9.0"), true, "문자열 비교가 아니라 숫자 비교다");
assert.equal(isNewer("1.0.0", "0.99.99"), true);
});
test("프리릴리스는 같은 숫자의 정식 버전보다 낮다", () => {
assert.equal(isNewer("1.0.0", "1.0.0-rc.1"), true);
assert.equal(isNewer("1.0.0-rc.1", "1.0.0"), false);
assert.ok(compareVersions("1.0.0-rc.2", "1.0.0-rc.1") > 0);
assert.ok(compareVersions("1.0.0-rc.10", "1.0.0-rc.9") > 0);
assert.equal(compareVersions("1.0.0+build5", "1.0.0"), 0);
});
test("displayWidth 는 한글을 2칸으로 센다", () => {
assert.equal(displayWidth("abc"), 3);
assert.equal(displayWidth("위치"), 4);
assert.equal(displayWidth("CLI 버전"), 8);
assert.equal(displayWidth("\x1b[31mab\x1b[0m"), 2, "ANSI 이스케이프는 폭이 아니다");
});
test("padDisplay 와 table 은 한글이 섞여도 값 열이 같은 칸에서 시작한다", () => {
assert.equal(displayWidth(padDisplay("위치", 8)), 8);
const lines = table([
["위치", "a"],
["CLI 버전", "b"],
["Node", "c"],
]).split("\n");
const starts = lines.map((l) => displayWidth(l.slice(0, l.search(/[abc]$/))));
assert.equal(new Set(starts).size, 1, `값 열 시작 칸이 제각각이다: ${starts}`);
});
test("heading 밑줄은 표시 폭을 기준으로 한다", () => {
const rule = (heading("설치 기록").split("\n")[2] ?? "").replace(/\x1b\[[0-9;]*m/g, "");
assert.equal([...rule].length, displayWidth("설치 기록") + 8);
});
test("fold 는 max 를 넘는 항목을 접는다", () => {
assert.deepEqual(fold(["a", "b"], 3), ["a", "b"]);
assert.equal(fold(["a", "b", "c", "d"], 2).length, 3);
});