The owner, after the Plugins page's README bird (722483c08): every skeleton loader should have it, the slow pages most of all (Sessions, Usage, Masking, Library). app.js keeps one bird for the window (skelBird). Every 250ms it looks for .skeleton and the Plugins page's ghost cards' .sk bars. When some have stayed 450ms or more and at least one can be seen (in the viewport, elementFromPoint at the bar landing on it or a box it sits in, since ghost bars let clicks through), the bird drops onto one. The bar dips under it, and it hops to the next bar it can see, in page order. When the bars are gone it flaps off up and to the right and is removed. It is position: fixed with pointer-events none, so nothing under it moves or stops taking clicks. A quick load (under 450ms) never shows it. A hidden window and reduced motion skip it. The README's bird (plugins.js bounceLoader) now draws from the same markup (BIRD) and styles (.sk-bird, sk-flap in app.css). plugins.css loses its .pm-bird copy. Budgets: app.js 1,321,319 -> 1,325,845, core 1,537,645 -> 1,541,967, the exact bytes, no room added. Run at origin/main9809a8ac9(load 100-150): - skeleton-bird.test.cjs (new), both engines: a held market read shows the bird within 3s, over 30 places and dips, and gone 2s after the reply. A 150ms reply shows none. Reduced motion: no bird, no dip. - plugin-readme-bird, i18n-keys, gateway-key-limit, the Budget tests: ok (the README bird's one webkit red is main's too, fixed in the next commit but one). - Probe with every /api read but state held, per page: the bird shows on Sessions (4 bars), Library (31), Providers (20), Gateway (39), Usage (15), Masking (2) and Plugins (48). Screenshots looked at for Library, Usage and Sessions. - The whole GUI suite ata6c808b68(concurrency 6, load ~170): 128 reds on this branch, 130 on main, over the same 36 files. Run alone twice per tree, the only test red on this branch and not on main was gateway-key-limit's chromium narrow check, a ResizeObserver race, fixed in the next commit. Broken by hand: with the bird never spawned, the slow test is red. Not tried: the Routing window page, which draws its stage at once and has no skeleton (the tray panel's routing tab does); the tray panel itself; the real app (only Playwright's engines).
108 lines
6.2 KiB
JavaScript
108 lines
6.2 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// What is loading has magpie's bird on it (the owner, 10-26): skeletons
|
|
// still up after a moment, as on a slow page, get the bird, which hops from
|
|
// bar to bar, each bar dipping under it, and flies off once they are gone.
|
|
// A quick load never sees it, and with reduced motion no bird comes.
|
|
const assert = require("node:assert/strict");
|
|
const fs = require("node:fs/promises");
|
|
const path = require("node:path");
|
|
const { test } = require("node:test");
|
|
const { chromium, webkit } = require("playwright");
|
|
|
|
const assets = path.resolve(__dirname, "../assets");
|
|
const listings = [{ package: "opencode-copilot-auth", name: "GitHub Copilot", icon: "githubcopilot", providers: ["github-copilot"],
|
|
summary: { en: "Your GitHub Copilot plan." }, npm: { version: "0.0.9", weekly: 48213, publisher: "thdxr" } }];
|
|
|
|
function server(market) {
|
|
return async (route) => {
|
|
const url = new URL(route.request().url());
|
|
const json = (data) => route.fulfill({ json: data });
|
|
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"en",theme:"light",web:false};` });
|
|
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
|
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang: "en", theme: "light" } });
|
|
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true }, plugins: [] });
|
|
if (url.pathname === "/api/groups") return json({ groups: [], pools: [] });
|
|
const state = { bun: true, bunVersion: "1.3.0", plugins: [] };
|
|
if (url.pathname === "/api/plugins/market") { await market(); return json({ listings, state }); }
|
|
if (url.pathname === "/api/plugins") return json(state);
|
|
if (url.pathname === "/api/plugins/listings") { await market(); return json({ listings }); }
|
|
if (url.pathname.startsWith("/api/")) return json({});
|
|
if (!/^\/[\w./-]*$/.test(url.pathname) || url.host !== "magpie.test") return route.fulfill({ status: 404, body: "" });
|
|
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
|
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
|
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
|
|
};
|
|
}
|
|
|
|
async function open(browser, reduced, market) {
|
|
const page = await (await browser.newContext({ viewport: { width: 980, height: 820 }, reducedMotion: reduced ? "reduce" : "no-preference" })).newPage();
|
|
page.setDefaultTimeout(5000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.addInitScript(() => {
|
|
// every bird that came, and every bar that dipped
|
|
window.seen = { birds: 0, places: new Set(), dips: 0 };
|
|
new MutationObserver((ms) => { for (const m of ms) for (const n of m.addedNodes) if (n.classList?.contains("sk-bird")) seen.birds++; })
|
|
.observe(document, { childList: true, subtree: true });
|
|
const step = () => {
|
|
const b = document.querySelector(".sk-bird.roam");
|
|
if (b) seen.places.add(b.style.transform);
|
|
seen.dips = Math.max(seen.dips, document.getAnimations().filter((a) => a.effect?.target?.matches?.(".skeleton, .pm-card.ghost .sk")
|
|
&& a.effect.getKeyframes().some((k) => /translateY/.test(k.transform || ""))).length);
|
|
requestAnimationFrame(step);
|
|
};
|
|
requestAnimationFrame(step);
|
|
});
|
|
await page.route("**/*", server(market));
|
|
await page.goto("http://magpie.test/?view=plugins");
|
|
return { page, errors };
|
|
}
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
const launch = () => (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
|
|
test(engine + ": a slow page's skeletons get the bird, hopping bar to bar, and it flies off when they go", async (t) => {
|
|
const browser = await launch();
|
|
t.after(() => browser.close());
|
|
let release;
|
|
const held = new Promise((r) => { release = r; });
|
|
const { page, errors } = await open(browser, false, () => held);
|
|
await page.locator("#view-plugins .pm-card.ghost").first().waitFor();
|
|
await page.locator(".sk-bird.roam").waitFor({ state: "attached", timeout: 3000 });
|
|
await page.waitForFunction(() => seen.places.size > 30 && seen.dips > 0, null, { timeout: 4000 });
|
|
const feet = await page.evaluate(() => {
|
|
const r = document.querySelector(".sk-bird.roam svg").getBoundingClientRect();
|
|
return { w: r.width, h: r.height };
|
|
});
|
|
assert(feet.w > 10 && feet.h > 10, `the bird is drawn: ${JSON.stringify(feet)}`);
|
|
release();
|
|
await page.waitForFunction(() => !document.querySelector("#view-plugins .pm-card.ghost"));
|
|
await page.waitForFunction(() => !document.querySelector(".sk-bird"), null, { timeout: 2000 });
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
|
|
test(engine + ": a quick load never sees the bird", async (t) => {
|
|
const browser = await launch();
|
|
t.after(() => browser.close());
|
|
const { page, errors } = await open(browser, false, () => new Promise((r) => setTimeout(r, 150)));
|
|
await page.waitForFunction(() => !document.querySelector("#view-plugins .pm-card.ghost"));
|
|
await page.waitForTimeout(800);
|
|
assert.equal(await page.evaluate(() => seen.birds), 0, "no bird came");
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
|
|
test(engine + ": with reduced motion no bird comes and no bar moves", async (t) => {
|
|
const browser = await launch();
|
|
t.after(() => browser.close());
|
|
let release;
|
|
const held = new Promise((r) => { release = r; });
|
|
const { page, errors } = await open(browser, true, () => held);
|
|
await page.locator("#view-plugins .pm-card.ghost").first().waitFor();
|
|
await page.waitForTimeout(1200);
|
|
assert.deepEqual(await page.evaluate(() => [seen.birds, seen.dips]), [0, 0]);
|
|
release();
|
|
await page.waitForFunction(() => !document.querySelector("#view-plugins .pm-card.ghost"));
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|