Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : MacLustr Command Center (MCC)8 * File : apps/web/e2e/specs/10-report.spec.ts9 * Module : web10 * Repository : https://git.spboucher.ai/maclustr-command-center11 * Project Website : https://clustr.spboucher.ai12 * Created : 2026-11-1813 * Last Modified : 2026-11-1814 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142import { mkdirSync, writeFileSync } from "node:fs";43import { dirname, join, resolve } from "node:path";44import { fileURLToPath } from "node:url";45import { expect, test } from "@playwright/test";46import { touchNodes } from "../lib/fixtures";47import { settled, signedIn, newClient } from "../lib/harness";48import { SCREENS } from "../lib/screens";4950const here = dirname(fileURLToPath(import.meta.url));51const web = resolve(here, "../..");52const shots = resolve(web, "../../docs/screenshots/web");5354// Measurements for the phase report (numbers are written to test-results/first-load.json, nothing is asserted55// beyond sanity) and, on request, the reference screenshots (MCC_E2E_SCREENSHOTS=1).56test.describe.serial("report: first-load weight and screenshots", () => {57 test("first-load JavaScript and CSS per route (cold cache, as transferred and decoded)", async ({ browser }) => {58 const { context, page } = await signedIn(browser, "e2e-owner");59 const cdp = await context.newCDPSession(page);60 await cdp.send("Network.enable");61 await cdp.send("Network.setCacheDisabled", { cacheDisabled: true });62 const rows: Record<string, unknown>[] = [];63 for (const s of [{ name: "signin", path: "/signin", testid: "" }, ...SCREENS.map((x) => ({ name: x.name, path: x.path, testid: x.testid }))]) {64 const seen = new Map<string, { type: string; encoded: number }>();65 const onResponse = (e: { requestId: string; type: string; response: { url: string; mimeType: string } }) => {66 const kind = /javascript/.test(e.response.mimeType) ? "js" : /css/.test(e.response.mimeType) ? "css" : "";67 if (kind) seen.set(e.requestId, { type: kind, encoded: 0 });68 };69 const onFinished = (e: { requestId: string; encodedDataLength: number }) => {70 const r = seen.get(e.requestId);71 if (r) r.encoded = e.encodedDataLength;72 };73 cdp.on("Network.responseReceived", onResponse);74 cdp.on("Network.loadingFinished", onFinished);75 const p = s.name === "signin" ? await (await newClient(browser, { conditional: true })).newPage() : page;76 const c = s.name === "signin" ? await p.context().newCDPSession(p) : null;77 if (c) {78 await c.send("Network.enable");79 await c.send("Network.setCacheDisabled", { cacheDisabled: true });80 c.on("Network.responseReceived", onResponse);81 c.on("Network.loadingFinished", onFinished);82 }83 const t0 = Date.now();84 await p.goto(s.path, { waitUntil: "load" });85 if (s.testid) await expect(p.getByTestId(s.testid)).toBeVisible();86 await settled(p);87 const ms = Date.now() - t0;88 const decoded = await p.evaluate(() => {89 const out = { js: 0, css: 0 };90 for (const e of performance.getEntriesByType("resource") as PerformanceResourceTiming[]) {91 if (e.initiatorType === "script" || /\.js(\?|$)/.test(e.name)) out.js += e.decodedBodySize;92 else if (/\.css(\?|$)/.test(e.name)) out.css += e.decodedBodySize;93 }94 return out;95 });96 const nav = await p.evaluate(() => {97 const n = performance.getEntriesByType("navigation")[0] as PerformanceNavigationTiming | undefined;98 const fcp = performance.getEntriesByName("first-contentful-paint")[0]?.startTime;99 return { domContentLoaded: n ? Math.round(n.domContentLoadedEventEnd) : null, load: n ? Math.round(n.loadEventEnd) : null, fcp: fcp ? Math.round(fcp) : null };100 });101 const sum = (t: string) => [...seen.values()].filter((r) => r.type === t).reduce((n, r) => n + r.encoded, 0);102 rows.push({ route: s.path, js_transferred_bytes: sum("js"), js_decoded_bytes: decoded.js, css_transferred_bytes: sum("css"), css_decoded_bytes: decoded.css, js_files: [...seen.values()].filter((r) => r.type === "js").length, ...nav, until_settled_ms: ms });103 cdp.off("Network.responseReceived", onResponse);104 cdp.off("Network.loadingFinished", onFinished);105 if (s.name === "signin") await p.context().close();106 }107 mkdirSync(join(web, "test-results"), { recursive: true });108 writeFileSync(join(web, "test-results", "first-load.json"), JSON.stringify({ measured_at: new Date().toISOString(), note: "Local loopback through control-api, Chromium, cold HTTP cache, production build.", routes: rows }, null, 2));109 for (const r of rows) console.log(`first-load ${String(r.route).padEnd(14)} JS ${(Number(r.js_transferred_bytes) / 1024).toFixed(0)} kB transferred / ${(Number(r.js_decoded_bytes) / 1024).toFixed(0)} kB decoded · CSS ${(Number(r.css_transferred_bytes) / 1024).toFixed(1)} kB · FCP ${String(r.fcp)} ms`);110 expect(rows.length).toBe(SCREENS.length + 1);111 await context.close();112 });113114 test("screenshots of the main screens (dark theme, French)", async ({ browser }) => {115 test.skip(process.env.MCC_E2E_SCREENSHOTS !== "1", "set MCC_E2E_SCREENSHOTS=1 to regenerate docs/screenshots/web");116 test.setTimeout(180_000);117 mkdirSync(shots, { recursive: true });118 const anon = await newClient(browser, { conditional: true });119 const a = await anon.newPage();120 await a.goto("/signin");121 await expect(a.getByTestId("signin-button")).toBeVisible();122 await a.screenshot({ path: join(shots, "00-signin.png") });123 await anon.close();124125 const { context, page } = await signedIn(browser, "e2e-owner");126 try { touchNodes(); } catch { /* fixtures absent while the cluster endpoints are not live */ }127 for (const s of SCREENS) {128 await page.goto(s.path);129 await settled(page);130 await expect(page.getByTestId(s.testid)).toBeVisible();131 await page.waitForTimeout(400);132 await page.screenshot({ path: join(shots, `${s.shot ?? s.name}.png`), fullPage: true });133 }134 const first = await page.evaluate(async () => ((await (await fetch("/api/v1/nodes?limit=1&sort=alias")).json()) as { items?: { id: string }[] }).items?.[0]?.id ?? null).catch(() => null);135 if (first) {136 await page.goto(`/nodes/${first}`);137 await settled(page);138 await page.screenshot({ path: join(shots, "03-node-detail.png"), fullPage: true });139 await page.goto(`/nodes/${first}?tab=metrics`);140 await settled(page);141 await page.waitForTimeout(600);142 await page.screenshot({ path: join(shots, "03-node-metrics.png"), fullPage: true });143 }144 for (const [path, name] of [["/settings/security", "14-settings-security"], ["/settings/invitations", "15-settings-invitations"], ["/settings/system", "16-settings-system"], ["/ops", "17-operations-centre"]] as const) {145 await page.goto(path);146 await settled(page);147 await page.waitForTimeout(300);148 await page.screenshot({ path: join(shots, `${name}.png`), fullPage: true });149 }150 await page.setViewportSize({ width: 390, height: 844 });151 await page.goto("/");152 await settled(page);153 await page.screenshot({ path: join(shots, "18-mobile-overview.png") });154 await page.goto("/maintenance");155 await settled(page);156 await page.screenshot({ path: join(shots, "19-mobile-maintenance.png") });157 await context.close();158 });159});160