完成80%

This commit is contained in:
2026-07-27 06:50:07 +08:00
parent 8475bbd19a
commit 1eae3bbef4
63 changed files with 13664 additions and 280 deletions
+16 -5
View File
@@ -16,7 +16,7 @@ const routeEnd = Number(process.env.PAGE_AUDIT_END || 0);
const wait = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));
const pageExpectations = {
"pages/auth/a01-entry": { title: "", noReload: true, skipTitle: true },
"pages/auth/a01-entry": { title: "", noReload: true, skipTitle: true, allowAuthenticatedRedirect: true },
"pages/auth/a04-register": { title: "注册账号" },
"pages/auth/a05-reset-password": { title: "重设密码" },
"pages/genealogy/g01-my-genealogies": { title: "我的家谱", capture: "01-genealogies.png" },
@@ -47,7 +47,7 @@ const pageExpectations = {
"pages/family/f10-video-list": { title: "家族视频", query: `genealogyId=${genealogyId}` },
"pages/records/r01-people-list": { title: "人物录", query: `genealogyId=${genealogyId}` },
"pages/records/r02-person-detail": { title: "人物详情", query: `genealogyId=${genealogyId}&state=error` },
"pages/records/r03-gift-list": { title: "亲友往来", query: `genealogyId=${genealogyId}`, capture: "05-gifts.png" },
"pages/records/r03-gift-list": { title: "贺礼簿", query: `genealogyId=${genealogyId}`, capture: "05-gifts.png" },
"pages/records/r04-gift-editor": { title: "新建往来记录", query: `genealogyId=${genealogyId}&mode=create` },
"pages/records/r05-ritual-list": { title: "礼仪活动", query: `genealogyId=${genealogyId}` },
"pages/records/r06-ritual-detail": { title: "礼仪详情", query: `genealogyId=${genealogyId}&ceremonyId=0` },
@@ -111,13 +111,24 @@ const waitFor = async (send, expression, message) => {
};
const open = async (send, route, noReload) => {
const expectation = pageExpectations[route];
const url = `${origin}/#/${route}${pageExpectations[route].query ? `?${pageExpectations[route].query}` : ""}`;
await send("Page.navigate", { url });
await waitFor(send, `location.href === ${JSON.stringify(url)}`, `navigation failed: ${route}`);
const authenticatedRedirect = `${origin}/#/pages/genealogy/g01-my-genealogies`;
const expectedLocation = pageExpectations[route].allowAuthenticatedRedirect
? `location.href === ${JSON.stringify(url)} || location.href === ${JSON.stringify(authenticatedRedirect)}`
: `location.href === ${JSON.stringify(url)}`;
await waitFor(send, expectedLocation, `navigation failed: ${route}`);
if (!expectation.skipTitle) {
await waitFor(send, `document.body?.innerText.includes(${JSON.stringify(expectation.title)})`, `title did not render: ${route}`);
}
if (!noReload) {
const previousTimeOrigin = await evaluate(send, "performance.timeOrigin");
await send("Page.reload");
send("Page.reload").catch(() => {});
await waitFor(send, `performance.timeOrigin !== ${JSON.stringify(previousTimeOrigin)}`, `reload failed: ${route}`);
if (!expectation.skipTitle) {
await waitFor(send, `document.body?.innerText.includes(${JSON.stringify(expectation.title)})`, `title did not render after reload: ${route}`);
}
}
await waitFor(send, "document.body && document.body.innerText.length > 0", `page did not render: ${route}`);
await wait(700);
@@ -131,7 +142,7 @@ const capture = async (send, filename) => {
const run = async () => {
const allRoutes = require("../pages.json").pages.map((page) => page.path);
assert.deepStrictEqual(allRoutes.sort(), Object.keys(pageExpectations).sort(), "route coverage drifted from pages.json");
assert.deepStrictEqual([...allRoutes].sort(), Object.keys(pageExpectations).sort(), "route coverage drifted from pages.json");
const routes = routeEnd > routeStart ? allRoutes.slice(routeStart, routeEnd) : allRoutes;
const { socket, send } = await connect();
const results = [];