fix: 忽略空图片并收紧预览警告断言
This commit is contained in:
1 parent
34504c0b44
commit
a1b29cedee
4 files changed
+34
-9
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"schemaVersion": 1,
|
"schemaVersion": 1,
|
||||||
"scope": "模板完成证据登记,保留命令、日志与产物哈希",
|
"scope": "模板完成证据登记,保留命令、日志与产物哈希",
|
||||||
"generatedAt": "2026-10-23T06:26:00.678Z",
|
"generatedAt": "2026-10-23T06:32:05.523Z",
|
||||||
"templates": {
|
"templates": {
|
||||||
"acheng-campus-food": {
|
"acheng-campus-food": {
|
||||||
"real-manifest-interaction": {
|
"real-manifest-interaction": {
|
||||||
@@ -256,5 +256,5 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sourceTreeHash": "e9ba4ece3d4b8d81e7afb2f0b62fb9c02468cf9a7da08ef80486c707f2667242"
|
"sourceTreeHash": "1e2a205c5faf17468eddc4526c462f9d7d749447d7e43c4087fb6b08f8244223"
|
||||||
}
|
}
|
||||||
@@ -115,16 +115,18 @@ export const Label = element("label");
|
|||||||
export const Image = React.forwardRef(({ mode, src, style, ...props }, ref) => {
|
export const Image = React.forwardRef(({ mode, src, style, ...props }, ref) => {
|
||||||
const key = React.useContext(TemplateAssetContext);
|
const key = React.useContext(TemplateAssetContext);
|
||||||
const assets = React.useContext(TemplatePreviewAssetsContext);
|
const assets = React.useContext(TemplatePreviewAssetsContext);
|
||||||
|
const normalizedSrc = typeof src === "string" ? src.trim() : "";
|
||||||
|
if (!normalizedSrc) return null;
|
||||||
return React.createElement("img", {
|
return React.createElement("img", {
|
||||||
...props,
|
...props,
|
||||||
ref,
|
ref,
|
||||||
src:
|
src:
|
||||||
assets && typeof src === "string" && src.startsWith("/assets/")
|
assets && normalizedSrc.startsWith("/assets/")
|
||||||
? // 导入包资源以 /assets 开头;本地多模板预览的 renderer 可能额外携带包 key 前缀。
|
? // 导入包资源以 /assets 开头;本地多模板预览的 renderer 可能额外携带包 key 前缀。
|
||||||
(assets[src]?.dataUrl ??
|
(assets[normalizedSrc]?.dataUrl ??
|
||||||
assets[src.replace(`/assets/${key}/`, "/assets/")]?.dataUrl ??
|
assets[normalizedSrc.replace(`/assets/${key}/`, "/assets/")]?.dataUrl ??
|
||||||
src)
|
normalizedSrc)
|
||||||
: resolveImageSource(src, key),
|
: resolveImageSource(normalizedSrc, key),
|
||||||
style: { objectFit: mode === "aspectFit" ? "contain" : "cover", ...style },
|
style: { objectFit: mode === "aspectFit" ? "contain" : "cover", ...style },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -98,7 +98,9 @@ test.beforeEach(({ page }) => {
|
|||||||
const isWarning =
|
const isWarning =
|
||||||
message.type() === "warning" ||
|
message.type() === "warning" ||
|
||||||
(message.type() === "error" &&
|
(message.type() === "error" &&
|
||||||
(text.startsWith("Warning:") || text.includes("non-boolean attribute")));
|
(text.startsWith("Warning:") ||
|
||||||
|
text.includes("non-boolean attribute") ||
|
||||||
|
text.includes("empty string")));
|
||||||
if (isWarning) warnings.push(text);
|
if (isWarning) warnings.push(text);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,28 @@
|
|||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import { test, expect } from "@playwright/test";
|
import { test, expect, type Page } from "@playwright/test";
|
||||||
|
|
||||||
const adminOrigin = process.env.ADMIN_URL || "http://localhost:3005";
|
const adminOrigin = process.env.ADMIN_URL || "http://localhost:3005";
|
||||||
|
const consoleWarnings = new WeakMap<Page, string[]>();
|
||||||
|
|
||||||
|
test.beforeEach(({ page }) => {
|
||||||
|
const warnings: string[] = [];
|
||||||
|
consoleWarnings.set(page, warnings);
|
||||||
|
page.on("console", (message) => {
|
||||||
|
const text = message.text();
|
||||||
|
const isWarning =
|
||||||
|
message.type() === "warning" ||
|
||||||
|
(message.type() === "error" &&
|
||||||
|
(text.startsWith("Warning:") ||
|
||||||
|
text.includes("non-boolean attribute") ||
|
||||||
|
text.includes("empty string")));
|
||||||
|
if (isWarning) warnings.push(text);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test.afterEach(({ page }) => {
|
||||||
|
expect(consoleWarnings.get(page) ?? []).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
const templateContent = JSON.parse(
|
const templateContent = JSON.parse(
|
||||||
fs.readFileSync("../../packages/template-acheng-campus-food/template.json", "utf8"),
|
fs.readFileSync("../../packages/template-acheng-campus-food/template.json", "utf8"),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in new issue
Block a user