34 lines
1.4 KiB
TypeScript
34 lines
1.4 KiB
TypeScript
import { test, expect } from "bun:test";
|
|
import { mkdtempSync, writeFileSync, rmSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { runDesignCommand } from "../src/design.ts";
|
|
|
|
test("design CLI validates data, inspects provenance and compiles without modifying input", async () => {
|
|
const directory = mkdtempSync(join(tmpdir(), "wrn-design-cli-"));
|
|
try {
|
|
const file = join(directory, "system.json");
|
|
const source = JSON.stringify({
|
|
schemaVersion: 1,
|
|
id: "square",
|
|
name: "Square",
|
|
version: "1",
|
|
tokens: { radius: { type: "dimension", value: "0", legacy: "radius-sm" } },
|
|
});
|
|
writeFileSync(file, source);
|
|
expect(JSON.parse(await runDesignCommand(["validate", file])).valid).toBe(true);
|
|
expect(JSON.parse(await runDesignCommand(["inspect", file])).tokens.radius.source).toBe(
|
|
"square.tokens.radius",
|
|
);
|
|
expect(await runDesignCommand(["compile", file])).toContain("--wrn-radius-sm:0;");
|
|
expect(await Bun.file(file).text()).toBe(source);
|
|
await expect(runDesignCommand(["compile", file, "--unknown=x"])).rejects.toThrow(
|
|
"WRN-DS-OPTION",
|
|
);
|
|
writeFileSync(file, source.replace('"0"', '"url(bad)"'));
|
|
await expect(runDesignCommand(["validate", file])).rejects.toThrow("WRN-DS-VALUE");
|
|
} finally {
|
|
rmSync(directory, { recursive: true, force: true });
|
|
}
|
|
});
|