60%
This commit is contained in:
@@ -1,20 +1,18 @@
|
||||
"use strict";
|
||||
|
||||
const assert = require("assert");
|
||||
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
|
||||
const origin = process.argv[2] || "http://localhost:5173";
|
||||
const cdpPort = process.env.CDP_PORT || "9222";
|
||||
const genealogyId = process.env.GENEALOGY_ID || "2080557121112465409";
|
||||
const wait = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));
|
||||
|
||||
const connect = async () => {
|
||||
const pages = await (await fetch("http://127.0.0.1:9222/json/list")).json();
|
||||
const page = pages.find(
|
||||
(candidate) => candidate.type === "page" && candidate.url.startsWith(`${origin}/`),
|
||||
);
|
||||
const pages = await (await fetch(`http://127.0.0.1:${cdpPort}/json`)).json();
|
||||
const page = pages.find((candidate) => candidate.type === "page" && candidate.url.startsWith(`${origin}/`));
|
||||
if (!page) throw new Error(`Chrome debugging has no ${origin} project page`);
|
||||
const socket = new WebSocket(page.webSocketDebuggerUrl);
|
||||
await new Promise((resolve, reject) => {
|
||||
socket.addEventListener("open", resolve, { once: true });
|
||||
socket.addEventListener("error", reject, { once: true });
|
||||
});
|
||||
await new Promise((resolve, reject) => { socket.addEventListener("open", resolve, { once: true }); socket.addEventListener("error", reject, { once: true }); });
|
||||
let id = 0;
|
||||
const pending = new Map();
|
||||
socket.addEventListener("message", (event) => {
|
||||
@@ -22,145 +20,68 @@ const connect = async () => {
|
||||
const request = pending.get(message.id);
|
||||
if (!request) return;
|
||||
pending.delete(message.id);
|
||||
message.error
|
||||
? request.reject(new Error(message.error.message))
|
||||
: request.resolve(message.result);
|
||||
message.error ? request.reject(new Error(message.error.message)) : request.resolve(message.result);
|
||||
});
|
||||
const send = (method, params = {}) => new Promise((resolve, reject) => {
|
||||
id += 1;
|
||||
pending.set(id, { resolve, reject });
|
||||
socket.send(JSON.stringify({ id, method, params }));
|
||||
});
|
||||
const send = (method, params = {}) =>
|
||||
new Promise((resolve, reject) => {
|
||||
id += 1;
|
||||
pending.set(id, { resolve, reject });
|
||||
socket.send(JSON.stringify({ id, method, params }));
|
||||
});
|
||||
return { socket, send };
|
||||
};
|
||||
|
||||
const valueOf = async (send, expression) =>
|
||||
(await send("Runtime.evaluate", { expression, returnByValue: true })).result?.value;
|
||||
const valueOf = async (send, expression) => (await send("Runtime.evaluate", { expression, returnByValue: true, awaitPromise: true })).result?.value;
|
||||
const waitFor = async (send, expression, message) => {
|
||||
for (let attempt = 0; attempt < 60; attempt += 1) {
|
||||
for (let attempt = 0; attempt < 80; attempt += 1) {
|
||||
if (await valueOf(send, expression)) return;
|
||||
await sleep(100);
|
||||
await wait(100);
|
||||
}
|
||||
throw new Error(message);
|
||||
};
|
||||
let auditId = 0;
|
||||
const open = async (send, route, selector) => {
|
||||
auditId += 1;
|
||||
const url = `${origin}/?rBusiness=${auditId}#${route}`;
|
||||
const open = async (send, route) => {
|
||||
const url = `${origin}/#${route}`;
|
||||
await send("Page.navigate", { url });
|
||||
await waitFor(send, `location.href===${JSON.stringify(url)}`, `navigation failed: ${route}`);
|
||||
await waitFor(
|
||||
send,
|
||||
`Boolean(document.querySelector(${JSON.stringify(selector)}))`,
|
||||
`missing ${selector}: ${route}`,
|
||||
);
|
||||
await waitFor(send, `location.href === ${JSON.stringify(url)}`, `navigation failed: ${route}`);
|
||||
const previousTimeOrigin = await valueOf(send, "performance.timeOrigin");
|
||||
await send("Page.reload");
|
||||
await waitFor(send, `performance.timeOrigin !== ${JSON.stringify(previousTimeOrigin)}`, `reload failed: ${route}`);
|
||||
await waitFor(send, "document.body.innerText.length > 0", `page did not render: ${route}`);
|
||||
};
|
||||
const click = (send, selector) =>
|
||||
valueOf(send, `document.querySelector(${JSON.stringify(selector)})?.click()`);
|
||||
const inputAt = (send, selector, index, value) =>
|
||||
valueOf(
|
||||
send,
|
||||
`(() => { const input=document.querySelectorAll(${JSON.stringify(selector)})[${index}]; input.value=${JSON.stringify(value)}; input.dispatchEvent(new Event('input',{bubbles:true})); return input.value; })()`,
|
||||
);
|
||||
|
||||
const routes = [
|
||||
["/pages/records/r03-gift-list?genealogyId=1001", ".record-card"],
|
||||
["/pages/records/r04-gift-editor?genealogyId=1001&mode=create", ".form-card"],
|
||||
["/pages/records/r05-ritual-list?genealogyId=1001", ".record-card"],
|
||||
["/pages/records/r06-ritual-detail?genealogyId=1001&ceremonyId=501", ".detail-card"],
|
||||
["/pages/records/r07-ritual-editor?genealogyId=1001&mode=create", ".form-card"],
|
||||
["/pages/records/r08-growth-journal?genealogyId=1001&personId=101", ".timeline-card"],
|
||||
["/pages/records/r09-life-events?genealogyId=1001&personId=101", ".service-state--unavailable"],
|
||||
["/pages/records/r10-memo-list?genealogyId=1001", ".memo-card"],
|
||||
["/pages/records/r11-merit-records?genealogyId=1001", ".merit-card"],
|
||||
];
|
||||
|
||||
const run = async () => {
|
||||
const { socket, send } = await connect();
|
||||
try {
|
||||
await send("Page.enable");
|
||||
await send("Runtime.enable");
|
||||
for (const size of [
|
||||
{ width: 320, height: 568 },
|
||||
{ width: 412, height: 915 },
|
||||
]) {
|
||||
await send("Emulation.setDeviceMetricsOverride", {
|
||||
...size,
|
||||
deviceScaleFactor: 1,
|
||||
mobile: true,
|
||||
screenWidth: size.width,
|
||||
screenHeight: size.height,
|
||||
});
|
||||
for (const [route, selector] of routes) {
|
||||
await open(send, route, selector);
|
||||
const documentWidth = await valueOf(send, "document.documentElement.scrollWidth");
|
||||
assert(documentWidth <= size.width + 1, `${route} overflows at ${size.width}`);
|
||||
}
|
||||
const readbacks = [
|
||||
["/pages/records/r03-gift-list?genealogyId=" + genealogyId, "\u63a5\u53e3\u8054\u8c03\u9a8c\u8bc1\u4eb2\u53cb"],
|
||||
["/pages/records/r05-ritual-list?genealogyId=" + genealogyId, "\u63a5\u53e3\u8054\u8c03\u9a8c\u8bc1\u793c\u4eea\u6d3b\u52a8"],
|
||||
["/pages/records/r08-growth-journal?genealogyId=" + genealogyId, "\u63a5\u53e3\u8054\u8c03\u9a8c\u8bc1\u6210\u957f\u8bb0\u5f55"],
|
||||
["/pages/records/r10-memo-list?genealogyId=" + genealogyId, "\u63a5\u53e3\u8054\u8c03\u9a8c\u8bc1\u5907\u5fd8"],
|
||||
["/pages/records/r11-merit-records?genealogyId=" + genealogyId, "\u63a5\u53e3\u8054\u8c03\u9a8c\u8bc1\u529f\u5fb7"],
|
||||
];
|
||||
for (const [route, text] of readbacks) {
|
||||
await open(send, route);
|
||||
await waitFor(send, `document.body.innerText.includes(${JSON.stringify(text)})`, `service readback missing: ${route}`);
|
||||
assert.strictEqual(await valueOf(send, "Boolean(document.querySelector('.state-card .app-loading'))"), false, `page stuck loading: ${route}`);
|
||||
}
|
||||
|
||||
await open(send, "/pages/records/r08-growth-journal?genealogyId=1002&personId=101", ".timeline-state--invalid");
|
||||
await open(send, "/pages/records/r09-life-events", ".service-state--invalid");
|
||||
await open(send, "/pages/records/r08-growth-journal?genealogyId=" + genealogyId);
|
||||
await valueOf(send, "document.querySelector('.header-action')?.click()");
|
||||
await waitFor(send, "Boolean(document.querySelector('.form-card'))", "R08 create form did not open");
|
||||
assert.strictEqual(await valueOf(send, "document.querySelectorAll('.required-mark').length"), 1, "R08 required marker drifted");
|
||||
|
||||
await open(send, "/pages/records/r03-gift-list?genealogyId=1001", ".record-card");
|
||||
await click(send, ".record-card");
|
||||
await waitFor(
|
||||
send,
|
||||
"location.hash.includes('genealogyId=1001&mode=view&relativeId=301&sourceKey=R03')",
|
||||
"R03 did not open the scoped R04 record",
|
||||
);
|
||||
await open(send, "/pages/records/r10-memo-list?genealogyId=" + genealogyId);
|
||||
await valueOf(send, "document.querySelector('.header-action')?.click()");
|
||||
await waitFor(send, "Boolean(document.querySelector('.form-card'))", "R10 create form did not open");
|
||||
assert.strictEqual(await valueOf(send, "document.querySelectorAll('.required-mark').length"), 1, "R10 required marker drifted");
|
||||
|
||||
await open(send, "/pages/records/r05-ritual-list?genealogyId=1001", ".record-card");
|
||||
await click(send, ".record-card");
|
||||
await waitFor(
|
||||
send,
|
||||
"location.hash.includes('genealogyId=1001&ceremonyId=501&sourceKey=R05')",
|
||||
"R05 did not open the scoped R06 ceremony",
|
||||
);
|
||||
|
||||
await open(send, "/pages/records/r08-growth-journal?genealogyId=1001&personId=101", ".timeline-card");
|
||||
const growthCount = await valueOf(send, "document.querySelectorAll('.timeline-card').length");
|
||||
await click(send, ".header-action");
|
||||
await waitFor(send, "Boolean(document.querySelector('.app-dialog-layer'))", "R08 editor missing");
|
||||
await inputAt(send, ".dialog-form input", 0, "第一次远行");
|
||||
await click(send, ".app-dialog__actions .app-button:last-child");
|
||||
await waitFor(
|
||||
send,
|
||||
"document.querySelector('.preview-card')?.innerText.includes('第一次远行')",
|
||||
"R08 local preview missing",
|
||||
);
|
||||
assert.strictEqual(
|
||||
await valueOf(send, "document.querySelectorAll('.timeline-card').length"),
|
||||
growthCount,
|
||||
"R08 local preview must not enter the official timeline",
|
||||
);
|
||||
|
||||
await open(send, "/pages/records/r11-merit-records?genealogyId=1001", ".merit-card");
|
||||
const meritCount = await valueOf(send, "document.querySelectorAll('.merit-card').length");
|
||||
await click(send, ".header-action");
|
||||
await inputAt(send, ".dialog-form input", 0, "整理旧谱");
|
||||
await inputAt(send, ".dialog-form input", 1, "汤文清");
|
||||
await click(send, ".app-dialog__actions .app-button:last-child");
|
||||
await waitFor(
|
||||
send,
|
||||
"document.querySelector('.preview-card')?.innerText.includes('整理旧谱')",
|
||||
"R11 local preview missing",
|
||||
);
|
||||
assert.strictEqual(
|
||||
await valueOf(send, "document.querySelectorAll('.merit-card').length"),
|
||||
meritCount,
|
||||
"R11 local preview must not change the official count",
|
||||
);
|
||||
await open(send, "/pages/records/r11-merit-records?genealogyId=" + genealogyId);
|
||||
await valueOf(send, "document.querySelector('.header-action')?.click()");
|
||||
await waitFor(send, "Boolean(document.querySelector('.form-card'))", "R11 create form did not open");
|
||||
assert.strictEqual(await valueOf(send, "document.querySelectorAll('.required-mark').length"), 2, "R11 required marker drifted");
|
||||
process.stdout.write("R-BUSINESS-FLOW-RUNTIME-SMOKE PASS\n");
|
||||
} finally {
|
||||
try {
|
||||
await send("Emulation.clearDeviceMetricsOverride");
|
||||
} catch (_) {}
|
||||
socket.close();
|
||||
}
|
||||
} finally { socket.close(); }
|
||||
};
|
||||
|
||||
run().catch((error) => {
|
||||
process.stderr.write(`${error.stack || error.message}\n`);
|
||||
process.exit(1);
|
||||
});
|
||||
run().catch((error) => { process.stderr.write(`${error.stack || error.message}\n`); process.exit(1); });
|
||||
|
||||
Reference in New Issue
Block a user