gitoria

layouts

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitb31dc74db31dc74dusage: calendar (theme 76f99f6-era ContentFirst, user menu, ☰ menu) and tracker (theme 76f99f6, modal + pagination current, own current marker until hybriel#197) rowsmreb31dc74d/tests/same-output.mjs

6.6 KB

  1. // tests/same-output.mjs (layouts mission 002, from components.hybriel's): same-output baseline of a CODE-ONLY COPY of this tree.
  2. // node tests/same-output.mjs <tree copy> <outdir> (README "Run, test, deploy" → "Same output"; refuses a tree with .git)
  3. // Server on 8750 (cwd = tree), Chrome 8751-8759. Saves every HTTP answer of the site (crawled from / and the seeds below
  4. // over every same-origin link: pages, READMEs, docs, icons, css, manifest, worker, every browser module a page loads,
  5. // a 404, the search redirect), the hydrated DOM of every page at 1280 and 390, a file-upload drop on
  6. // /components/file-upload and a md-editor drop on /components/md-editor (the component's DOM afterwards), and the console
  7. // problems. Compare two runs with tests/same-output-compare.py (+ same-output-modules.py). Stops all by PID.
  8. import { spawn } from 'node:child_process';
  9. import { writeFileSync, mkdirSync, rmSync, existsSync } from 'node:fs';
  10. import { join, resolve } from 'node:path';
  11. import { createHash } from 'node:crypto';
  12. import { launchBrowser } from './cdp.mjs';
  13. if (!process.env.HL_CHROME && existsSync('/opt/google/chrome/chrome')) process.env.HL_CHROME = '/opt/google/chrome/chrome';
  14. const TREE = resolve(process.argv[2]), OUT = resolve(process.argv[3]);
  15. if (existsSync(join(TREE, '.git'))) { console.log('refused: ' + TREE + ' has .git — run it on a code-only copy'); process.exit(2); }
  16. const PORT = Number(process.env.SAME_OUTPUT_PORT || 8750), BASE = `http://127.0.0.1:${PORT}`;
  17. rmSync(OUT, { recursive: true, force: true }); mkdirSync(OUT, { recursive: true });
  18. const sleep = (ms) => new Promise(r => setTimeout(r, ms));
  19. let log = '';
  20. const server = spawn(join(TREE, 'bin/hybriel'), ['project.hl'], { cwd: TREE, env: { ...process.env, LAYOUTS_PORT: String(PORT), LAYOUTS_WATCH: '0' }, stdio: ['ignore', 'pipe', 'pipe'] });
  21. server.stdout.on('data', d => log += d); server.stderr.on('data', d => log += d);
  22. let browser = null;
  23. const n = { http: 0, dom: 0 };
  24. const save = (kind, key, text) => { writeFileSync(join(OUT, kind + '__' + key.replace(/\?v=\w+/, '').replace(/[^\w.-]+/g, '_')), text); n[kind === 'http' ? 'http' : 'dom']++; };
  25. try {
  26. for (let i = 0; ; i++) { try { if ((await fetch(BASE + '/')).ok) break; } catch {} if (i > 480) throw new Error('no server\n' + log); await sleep(250); }
  27. const seeds = ['/', '/search/modal', '/search?q=date+picker', '/favicon.ico', '/__hl/manifest.webmanifest', '/__hl/sw.js', '/theme/check-theme.mjs', '/nope', '/docs/nope.md'];
  28. const seen = new Set(), pages = [];
  29. const get = async (u) => {
  30. if (seen.has(u)) return; seen.add(u);
  31. const r = await fetch(BASE + u, { redirect: 'manual' }); const b = Buffer.from(await r.arrayBuffer());
  32. const ct = r.headers.get('content-type') || '';
  33. const body = /text|json|javascript|svg|markdown|css|manifest/.test(ct) ? b.toString('utf8') : 'sha256 ' + createHash('sha256').update(b).digest('hex');
  34. save('http', u, `${r.status} ${ct} ${r.headers.get('cache-control') || ''} ${r.headers.get('location') || ''}\n${body}`);
  35. if (r.status === 200 && /text\/html/.test(ct)) pages.push(u);
  36. if (/text\/html|javascript/.test(ct)) for (const m of body.matchAll(/["'(](\/(?:__hl\/[\w./-]+|[\w./-]+\.hl|icons\/[\w./-]+)(?:\?v=\w+)?)/g)) await get(m[1]);
  37. if (/text\/html/.test(ct)) for (const m of body.matchAll(/href="(\/[^"#?]*)"/g)) await get(m[1]);
  38. };
  39. for (const u of seeds) await get(u);
  40. browser = await launchBrowser({ debugPortRange: (process.env.SAME_OUTPUT_CHROME || "8751-8759").split("-").map(Number) });
  41. const page = await browser.newPage();
  42. const ev = (e) => page.evaluate(e);
  43. const hydrated = () => page.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1', { timeout: 30000, label: 'hydrated' });
  44. const dom = `(() => { const c = document.body.cloneNode(true); c.querySelectorAll('script').forEach(s => s.remove()); return c.outerHTML; })()`;
  45. for (const w of [1280, 390]) {
  46. await page.send('Emulation.setDeviceMetricsOverride', { width: w, height: w < 600 ? 844 : 900, deviceScaleFactor: 1, mobile: w < 600 });
  47. for (const p of pages) { await page.goto(BASE + p, { timeout: 45000 }); await hydrated(); await sleep(500); save('dom', w + p, await ev(dom)); }
  48. }
  49. await page.send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 900, deviceScaleFactor: 1, mobile: false });
  50. // file upload: drop a 300 KB file (the showcase answers done, keeps nothing)
  51. await page.goto(BASE + '/components/file-upload', { timeout: 45000 }); await hydrated(); await sleep(600);
  52. await ev(`(() => { const dt = new DataTransfer(); dt.items.add(new File([new Uint8Array(307200).map((_, i) => i % 251)], 'data.bin', { type: 'application/octet-stream' })); document.querySelector('file-upload drop-zone').dispatchEvent(new DragEvent('drop', { dataTransfer: dt, bubbles: true, cancelable: true })); })()`);
  53. await page.waitFor(`document.querySelector('file-upload .state').textContent === 'Uploaded'`, { timeout: 30000, label: 'uploaded' });
  54. await sleep(300); save('dom', 'upload-drop', await ev(`document.querySelector('file-upload').outerHTML`));
  55. // md-editor: drop a png and a .exe-named file into the second editor (the showcase answers /not-kept/<size>)
  56. await page.goto(BASE + '/components/md-editor', { timeout: 45000 }); await hydrated(); await sleep(600);
  57. const PNG = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==';
  58. await ev(`(() => { const ed = document.querySelectorAll('md-editor')[1]; const a = ed.querySelector('article'); a.focus(); const png = Uint8Array.from(atob('${PNG}'), c => c.charCodeAt(0)); const dt = new DataTransfer(); dt.items.add(new File([png], 'one.png', { type: 'image/png' })); dt.items.add(new File(['MZ'], 'run.exe', { type: 'application/octet-stream' })); a.dispatchEvent(new DragEvent('drop', { dataTransfer: dt, bubbles: true, cancelable: true, clientX: 50, clientY: 50 })); })()`);
  59. await page.waitFor(`document.querySelectorAll('md-editor')[1].querySelector('input.value').value.includes('run.exe')`, { timeout: 30000, label: 'md uploaded' });
  60. await sleep(500); save('dom', 'md-upload', await ev(`document.querySelector('show-md-editor').outerHTML`));
  61. const probs = page.problems().filter(m => !/favicon|Failed to load resource/.test(m.text));
  62. save('dom', 'console-problems', probs.map(m => m.text).join('\n'));
  63. console.log(`saved http ${n.http}, dom ${n.dom} (${pages.length} pages) -> ${OUT}`);
  64. } catch (e) { console.log('BASELINE FAILED', e.stack || e, '\n', log.slice(-2000)); process.exitCode = 1; }
  65. finally {
  66. if (browser) { try { await browser.close(); } catch {} }
  67. server.kill('SIGTERM'); await new Promise(r => { if (server.exitCode !== null) return r(); server.once('exit', r); setTimeout(r, 3000); });
  68. }

Branches

Latest commits

  • b31dc74dusage: calendar (theme 76f99f6-era ContentFirst, user menu, ☰ menu) and tracker (theme 76f99f6, modal + pagination current, own current marker until hybriel#197) rowsmre
  • 8a3d5d40Mission 010: brief, report, LOG, STATUSmre
  • a56abf1fSync components to components.hybriel 3794c59 (MdEditor real-key fixes); showcase real-key check on the md-editor pagemre
  • 76f99f64E2E in lisbeth's Chrome for the menu's current page (mission 009): tests/e2e-menu-current.mjs, reportmre
  • 159b1d53MainMenu/Sidebar: current page marked beyond colour, count badge, item current flag; gate 300/0 (mission 009)mre
  • 0573eed3usage: notes + tickets on MdEditor (md-editor.js retired), gitoria on theme dbe3de7, tracker theme oldermre
  • 78478f6eSync showcase to components.hybriel 1442e58: pick-mode page, comments attach, md-editor rows/files off; gates 285/0mre
  • dbe3de79Display bugs from a real Chrome walk (mission 007): Settings page and in-shell doc reader instead of raw .md links, closed phone search hidden whatever a page says, /elements form rules scoped, three-pane danger contrast; display audit gate (132 -> 244 checks), walk + Settings e2e toolsmre
  • 1875a051Theme: 44 px tap targets mobile first (layoutTap), 16 px fields, desktop denser only in @media 60rem; 390 px tap audit + gate checks (mission 006)mre
  • 3d4f8e19Sync showcase to components.hybriel 9db927d: comments and files-upload pages, pagination onPage, md-editor readonly, gate 99 checksmre
  • 64d635acmission brief 005mre
  • 0d0fef25paths: projects moved into /media/STORAGE/projects/WorldAPI/mre
  • 2dbe0df5Re-vendor Hybriel to the shared static build 0f396652 (plugins; bin/ is git-ignored), compose cache volume + tmpfs /tmp, gate wait 120 s, report 004mre
  • 0adc551emission brief 004mre
  • 1376e905deploy.sh: wait up to DEPLOY_URL_WAIT (120 s) for 200 after the restart, as the other apps (cold compile, hybriel#148)mre
  • c0fdbf6cdocker-compose: init: true (hybriel#156, PID 1 ignored SIGTERM, every restart waited 10 s)mre
  • ecf70665usage: layouts on components a567b57mre
  • 315731efcomponents re-synced to components.hybriel a567b57 (md-editor tables)mre
  • b59e2ee9docs/usage.md + tools/usage.sh: which app carries which component/theme/tokens copy, and whether it matches the sourcemre
  • 0222f67ctheme: two corner radii only (radiusSmall 5px, radiusLarge 10px); check-theme flags any other radius; gate 76/0mre