47 lines
1.5 KiB
TypeScript
47 lines
1.5 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 messageBlock = cssBlock(".form-error,\\s*\\n\\.form-success");
|
|
|
|
assertIncludes(messageBlock, "position: fixed;");
|
|
assertIncludes(messageBlock, "z-index: 120;");
|
|
assertIncludes(messageBlock, "left: 50%;");
|
|
assertIncludes(messageBlock, "right: auto;");
|
|
assertIncludes(messageBlock, "animation: toast-autohide");
|
|
assertIncludes(messageBlock, "pointer-events: none;");
|
|
assertNotIncludes(messageBlock, "right: 28px;");
|
|
assertIncludes(css, "@keyframes toast-autohide");
|
|
assertIncludes(css, "visibility: hidden;");
|
|
|
|
function cssBlock(selector: string): string {
|
|
const pattern = new RegExp(`${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}`);
|
|
}
|
|
}
|