]> acesimba.cloud Git - StationBuilder.git/commitdiff
test: add first-load timing script to reproduce incognito stuck-loading
authorroot <root@localhost.localdomain>
Wed, 9 Sep 2026 04:13:40 +0000 (12:13 +0800)
committerroot <root@localhost.localdomain>
Wed, 9 Sep 2026 04:13:40 +0000 (12:13 +0800)
Confirms loading state now resolves <1s on dev server (cold/warm) and public
nginx path after swappiness=1 + keepalive mitigation of swap-driven cold faults.

scripts/timing-firstload.mjs [new file with mode: 0644]

diff --git a/scripts/timing-firstload.mjs b/scripts/timing-firstload.mjs
new file mode 100644 (file)
index 0000000..cad2244
--- /dev/null
@@ -0,0 +1,37 @@
+import { chromium } from "playwright";
+
+const BASE = process.env.BASE || "http://127.0.0.1:37821/t/stationbuilder/";
+
+const run = async (label) => {
+  const browser = await chromium.launch();
+  const ctx = await browser.newContext(); // fresh = incognito-equivalent
+  const page = await ctx.newPage();
+  const t0 = Date.now();
+  let domReady = 0, loadingGone = 0;
+  page.on("domcontentloaded", () => { domReady = Date.now() - t0; });
+  try {
+    await page.goto(BASE, { waitUntil: "commit", timeout: 60000 });
+    // wait until the loading empty-state disappears (content resolves)
+    await page.waitForFunction(() => {
+      const els = Array.from(document.querySelectorAll(".empty-state"));
+      const txt = els.map(e => e.textContent || "").join("");
+      return !/加载中/.test(txt);
+    }, { timeout: 90000 });
+    loadingGone = Date.now() - t0;
+  } catch (e) {
+    console.log(`[${label}] FAIL: ${e.message} (domReady=${domReady}ms, loadingGone=${loadingGone}ms)`);
+    await browser.close();
+    return;
+  }
+  console.log(`[${label}] domContentLoaded=${domReady}ms, loadingResolved=${loadingGone}ms`);
+  await browser.close();
+};
+
+console.log("=== run 1 (cold) ===");
+await run("cold");
+console.log("=== run 2 (warm, same dev server) ===");
+await run("warm");
+const PUB = process.env.PUB || "https://aidemo.istation.cloud/t/stationbuilder/";
+console.log(`=== run 3 (public nginx: ${PUB}) ===`);
+await run("public");
+process.exit(0);