修正图表采样副作用与暂停时钟下的导航验收

This commit is contained in:
cieanyau committed 2026-11-06 03:22:56 +08:00
1 parent 4ac87fa574
commit 7362f22f98
1 file changed
+23 -10
+23 -10
View File
@@ -98,6 +98,11 @@ async function enterMonitor(page) {
(count) => count === 4, (count) => count === 4,
"The real monitor must render all four charts", "The real monitor must render all four charts",
); );
await eventually(
() => page.getByRole("button", { name: "刷新", exact: true }).isEnabled(),
Boolean,
"Initial chart responses must finish before observing available data",
);
// 先给无动画图表一个绘制帧,不把 Canvas 的创建本身误认为动画。 // 先给无动画图表一个绘制帧,不把 Canvas 的创建本身误认为动画。
await page.clock.runFor(50); await page.clock.runFor(50);
await page.mouse.move(0, 0); await page.mouse.move(0, 0);
@@ -107,15 +112,19 @@ async function enterMonitor(page) {
async function observeFrames(page, state) { async function observeFrames(page, state) {
const sample = () => const sample = () =>
page.locator(".chart-viewport canvas").evaluateAll((canvases) => page.locator(".chart-viewport canvas").evaluateAll((canvases) =>
canvases.map((canvas) => ({ canvases.map((canvas) => {
width: canvas.width, const image = canvas.toDataURL();
height: canvas.height, const blank = document.createElement("canvas");
painted: canvas blank.width = canvas.width;
.getContext("2d") blank.height = canvas.height;
.getImageData(0, 0, canvas.width, canvas.height) // 不对产品画布反复 getImageData:浏览器可能因此从 GPU 切到 CPU,制造一次性光栅差异。
.data.some((channel) => channel !== 0), return {
image: canvas.toDataURL(), width: canvas.width,
})), height: canvas.height,
painted: image !== blank.toDataURL(),
image,
};
}),
); );
const first = await sample(); const first = await sample();
assert.equal( assert.equal(
@@ -279,7 +288,11 @@ test(
.first() .first()
.click(); .click();
await eventually( await eventually(
() => page.locator(".chart-viewport canvas").count(), async () => {
// 导航也依赖浏览器任务/rAF;暂停时钟下只轮询 DOM 会阻止真实路由完成卸载。
await page.clock.runFor(50);
return page.locator(".chart-viewport canvas").count();
},
(count) => count === 0, (count) => count === 0,
"Leaving the instance must unmount the monitor charts", "Leaving the instance must unmount the monitor charts",
); );