52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
declare const process: { cwd(): string };
|
|
declare function require(name: string): {
|
|
readFileSync?: (path: string, encoding: string) => string;
|
|
join?: (...parts: string[]) => string;
|
|
};
|
|
|
|
const { readFileSync } = require("node:fs");
|
|
const { join } = require("node:path");
|
|
|
|
if (!readFileSync || !join) {
|
|
throw new Error("测试运行环境缺少文件读取能力");
|
|
}
|
|
|
|
const css = readFileSync(join(process.cwd(), "src/assets/styles.css"), "utf-8");
|
|
|
|
const loginVisual = cssBlock(".login-visual");
|
|
assertIncludes(loginVisual, "background: var(--surface-soft);");
|
|
assertIncludes(loginVisual, "color: var(--text);");
|
|
assertNotIncludes(loginVisual, "rgba(var(--primary-rgb), 0.94)");
|
|
|
|
const ledgerVisual = cssBlock(".ledger-visual");
|
|
assertIncludes(ledgerVisual, "background: var(--card);");
|
|
assertIncludes(ledgerVisual, "padding: 32px;");
|
|
|
|
const appearancePanel = cssBlock(".appearance-panel");
|
|
assertIncludes(appearancePanel, "width: min(480px, calc(100vw - 20px));");
|
|
|
|
function cssBlock(selector: string): string {
|
|
const pattern = new RegExp(`${escapeRegExp(selector)}\\s*\\{([\\s\\S]*?)\\n\\}`, "m");
|
|
const match = css.match(pattern);
|
|
if (!match) {
|
|
throw new Error(`缺少样式块 ${selector}`);
|
|
}
|
|
return match[1];
|
|
}
|
|
|
|
function assertIncludes(content: string, expected: string): void {
|
|
if (!content.includes(expected)) {
|
|
throw new Error(`期望包含 ${expected}`);
|
|
}
|
|
}
|
|
|
|
function assertNotIncludes(content: string, unexpected: string): void {
|
|
if (content.includes(unexpected)) {
|
|
throw new Error(`不应包含 ${unexpected}`);
|
|
}
|
|
}
|
|
|
|
function escapeRegExp(value: string): string {
|
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
}
|