fix(gate): 首页 CMS 退化按名字可判;视觉截图前等显影落定 #58
@@ -51,11 +51,16 @@ async function waitForPageStable(page: Page) {
|
||||
// 不能直接 `scrollTo(scrollHeight)` 一跳到底:IntersectionObserver 只会回调当前视口
|
||||
// 内的目标,中间各屏被跳过 ⇒ 截图出来是空白段(2026-10-20 移除路由级 AnimatePresence
|
||||
// 后首屏不再替子树屏蔽 initial,这条路径才真正被走到)。
|
||||
// dwell 由 120ms 提到 260ms 并排掉两帧:120ms 在 4 worker 抢 CPU 时不足以让
|
||||
// IO 回调 + framer 提交动画,中间某屏会被跳过(lessons §5.51)。
|
||||
await page.evaluate(async () => {
|
||||
const nextFrame = () =>
|
||||
new Promise<void>((resolve) => requestAnimationFrame(() => requestAnimationFrame(() => resolve())));
|
||||
const step = Math.max(400, Math.floor(window.innerHeight * 0.8));
|
||||
for (let y = 0; y <= document.body.scrollHeight; y += step) {
|
||||
window.scrollTo({ top: y, behavior: 'instant' });
|
||||
await new Promise((resolve) => setTimeout(resolve, 120));
|
||||
await new Promise((resolve) => setTimeout(resolve, 260));
|
||||
await nextFrame();
|
||||
}
|
||||
window.scrollTo({ top: document.body.scrollHeight, behavior: 'instant' });
|
||||
await new Promise((resolve) => setTimeout(resolve, 400));
|
||||
@@ -71,10 +76,52 @@ async function waitForPageStable(page: Page) {
|
||||
});
|
||||
});
|
||||
await page.waitForTimeout(1000);
|
||||
await page.evaluate(() => {
|
||||
document.fonts?.ready;
|
||||
});
|
||||
await page.evaluate(() => document.fonts?.ready);
|
||||
await page.waitForTimeout(500);
|
||||
|
||||
await assertCmsStateOk(page);
|
||||
await waitForRevealsSettled(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 等 whileInView 真正提交:framer 把未开始的动画写成 inline `opacity: 0`,
|
||||
* 完成后改写成 1。两者只差这一笔,所以按 inline style 判定即可。
|
||||
* 排除 display:none 与零高度元素(折叠菜单、屏外测距节点),避免把「本来就不可见」判成未提交。
|
||||
* 表达式以字符串传入:它在浏览器上下文求值,闭包里的 Node 侧变量带不过去。
|
||||
*/
|
||||
const PENDING_REVEALS_EXPR =
|
||||
"Array.from(document.querySelectorAll('main *')).filter((el) => el.style.opacity === '0' && getComputedStyle(el).display !== 'none' && el.getBoundingClientRect().height > 0)";
|
||||
|
||||
async function waitForRevealsSettled(page: Page) {
|
||||
try {
|
||||
await page.waitForFunction(`${PENDING_REVEALS_EXPR}.length === 0`, undefined, {
|
||||
timeout: 8000,
|
||||
polling: 100,
|
||||
});
|
||||
} catch {
|
||||
const total: number = await page.evaluate(`${PENDING_REVEALS_EXPR}.length`);
|
||||
const pending: string[] = await page.evaluate(
|
||||
`${PENDING_REVEALS_EXPR}.slice(0, 5).map((el) => el.tagName.toLowerCase() + '.' + String(el.className).split(' ').slice(0, 2).join('.'))`,
|
||||
);
|
||||
throw new Error(
|
||||
`${total} 个元素仍停在 inline opacity:0(whileInView 未提交):${pending.join(' , ')}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 首页把 CMS 读数状态写在 `data-cms-state` 上。退化时页面照常 200、只是整套落到常量版式,
|
||||
* 像素比对只会给出一团无从归因的差异 —— 在这里先按名字判一次。
|
||||
*/
|
||||
async function assertCmsStateOk(page: Page) {
|
||||
const marker = page.locator('main [data-cms-state]').first();
|
||||
if ((await marker.count()) === 0) return;
|
||||
const state = await marker.getAttribute('data-cms-state');
|
||||
if (state !== 'ok') {
|
||||
throw new Error(
|
||||
`CMS 数据退化:data-cms-state=${state};页面已回落到常量版式,像素比对无意义(lessons §5.51)`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
test.describe('L1: 全页面视觉回归测试', () => {
|
||||
|
||||
Reference in new issue
Block a user