Файли
openidea/src/styles/customProperties.test.ts
T
Mr0Bread 732baf8f1e fix(styles): use defined tokens where CSS read --bg-subtle, --bg-toolbar and --fg-primary (#3550)
Three custom properties were read without a fallback and declared nowhere, so they resolved to their initial values: no background on the Working Status and Command Permissions rows, none on the console Find button (its icon sat over console text), and an inherited hover colour. They now use --bg-hover, --bg-elev and --fg-strong; a dead var(--bg) fallback in Run.module.css is dropped. A test lists any var(--x) without a fallback whose --x is declared nowhere.

Co-authored-by: Mr0Bread <[email protected]>
2026-11-15 23:31:12 +08:00

39 рядки
1.6 KiB
TypeScript

// @vitest-environment node
/**
* A `var(--x)` with no fallback whose `--x` is declared nowhere resolves to the property's
* initial value: a transparent background, inherited text. Nothing else catches it, so this
* lists every such use.
*
* A name ending in `-` is the start of one assembled at runtime (`--diff-${kind}`).
*/
import { readdirSync, readFileSync } from "node:fs";
import { join } from "node:path";
import { expect, it } from "vitest";
const SRC = join(import.meta.dirname, "..");
function sources(dir: string): string[] {
return readdirSync(dir, { withFileTypes: true }).flatMap((e) => {
const path = join(dir, e.name);
if (e.isDirectory()) return sources(path);
return /\.(css|tsx?)$/.test(e.name) ? [path] : [];
});
}
it("every custom property read without a fallback is declared somewhere", () => {
const declared = new Set<string>();
const reads: { name: string; where: string }[] = [];
for (const path of sources(SRC)) {
const text = readFileSync(path, "utf8");
for (const m of text.matchAll(/(?<![\w-])(--[\w-]+)\s*:/g)) declared.add(m[1]!);
for (const m of text.matchAll(/["'`](--[\w-]+)/g)) declared.add(m[1]!); // setProperty("--x", …), { "--x": … }
if (/\.test\.tsx?$/.test(path)) continue;
for (const m of text.matchAll(/var\(\s*(--[\w-]+)\s*\)/g)) {
const line = text.slice(0, m.index).split("\n").length;
reads.push({ name: m[1]!, where: `${path.slice(SRC.length + 1)}:${line}` });
}
}
const undeclared = reads.filter((r) => !declared.has(r.name) && !r.name.endsWith("-"));
expect(undeclared.map((r) => `${r.name} at ${r.where}`)).toEqual([]);
});