test: 增加门窗行业视觉验收夹具
This commit is contained in:
1 parent
4b455f5688
commit
a05c578766
2 files changed
+45
-15
No files matched your search
@@ -1,21 +1,38 @@
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
const root = path.resolve(__dirname, "..");
|
||||
const fixtureFiles = ["linjing-door-visual.json", "minimal-neutral-visual.json"];
|
||||
const fixtures = fixtureFiles.map((file) => JSON.parse(fs.readFileSync(path.join(__dirname, "fixtures", file), "utf8")));
|
||||
const fixtureFiles = [
|
||||
"linjing-door-visual.json",
|
||||
"minimal-neutral-visual.json",
|
||||
"doors-visual.json",
|
||||
];
|
||||
const fixtures = fixtureFiles.map((file) =>
|
||||
JSON.parse(fs.readFileSync(path.join(__dirname, "fixtures", file), "utf8")),
|
||||
);
|
||||
for (const fixture of fixtures) {
|
||||
const failures = [];
|
||||
for (const [state, definition] of Object.entries(fixture.states)) {
|
||||
const wxmlPath = path.join(root, `${definition.page}.wxml`);
|
||||
if (!fs.existsSync(wxmlPath)) { failures.push(`${state}: missing ${definition.page}.wxml`); continue; }
|
||||
let content = fs.readFileSync(wxmlPath, "utf8");
|
||||
const componentRefs = [...content.matchAll(/<([a-z][a-z0-9-]*)\s/g)].map((match) => match[1]).filter((name) => name.includes("-"));
|
||||
for (const ref of componentRefs) {
|
||||
const candidate = path.join(root, "components/modules", ref, `${ref}.wxml`);
|
||||
if (fs.existsSync(candidate)) content += fs.readFileSync(candidate, "utf8");
|
||||
const failures = [];
|
||||
for (const [state, definition] of Object.entries(fixture.states)) {
|
||||
const wxmlPath = path.join(root, `${definition.page}.wxml`);
|
||||
if (!fs.existsSync(wxmlPath)) {
|
||||
failures.push(`${state}: missing ${definition.page}.wxml`);
|
||||
continue;
|
||||
}
|
||||
let content = fs.readFileSync(wxmlPath, "utf8");
|
||||
const componentRefs = [...content.matchAll(/<([a-z][a-z0-9-]*)\s/g)]
|
||||
.map((match) => match[1])
|
||||
.filter((name) => name.includes("-"));
|
||||
for (const ref of componentRefs) {
|
||||
const candidate = path.join(root, "components/modules", ref, `${ref}.wxml`);
|
||||
if (fs.existsSync(candidate)) content += fs.readFileSync(candidate, "utf8");
|
||||
}
|
||||
for (const anchor of definition.anchors)
|
||||
if (!content.includes(anchor)) failures.push(`${state}: missing anchor ${anchor}`);
|
||||
}
|
||||
for (const anchor of definition.anchors) if (!content.includes(anchor)) failures.push(`${state}: missing anchor ${anchor}`);
|
||||
}
|
||||
if (failures.length) { console.error(failures.join("\n")); process.exit(1); }
|
||||
console.log(`Visual fixture ${fixture.templateKey} passed: ${Object.keys(fixture.states).length} states at ${fixture.viewport.width}x${fixture.viewport.height}.`);
|
||||
if (failures.length) {
|
||||
console.error(failures.join("\n"));
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(
|
||||
`Visual fixture ${fixture.templateKey} passed: ${Object.keys(fixture.states).length} states at ${fixture.viewport.width}x${fixture.viewport.height}.`,
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user