← back to Schumacher Internal

scripts/verify-e2e.mjs

31 lines

// Spec verification gate: structural DOM invariant on Chromium + WebKit-with-creds-in-URL.
import { chromium, webkit } from 'playwright';
const AUTH = process.env.BASIC_AUTH || 'admin:DW2024!';
const PORT = process.env.PORT || 9946;
const BASE = `http://${AUTH}@127.0.0.1:${PORT}/`;
async function run(engine, name) {
  const b = await engine.launch();
  const p = await b.newPage();
  const errs = [];
  p.on('pageerror', e => errs.push('pageerror: ' + e.message));
  p.on('console', m => { if (m.type() === 'error') errs.push('console: ' + m.text()); });
  await p.goto(BASE, { waitUntil: 'networkidle', timeout: 30000 });
  await p.waitForSelector('.grid .card', { timeout: 15000 }).catch(() => {});
  const r = await p.evaluate(() => {
    const grid = document.querySelector('.grid');
    const cards = document.querySelectorAll('.card').length;
    const gridKids = grid ? grid.children.length : -1;
    const emptyAnchors = [...document.querySelectorAll('.grid > a')].filter(a => !a.textContent.trim() && !a.querySelector('img')).length;
    const panelTables = document.querySelectorAll('aside details, .panel details').length;
    return { cards, gridKids, emptyAnchors, panelTables };
  });
  await b.close();
  const ok = r.cards > 0 && r.gridKids === r.cards && r.emptyAnchors === 0;
  console.log(`[${name}] cards=${r.cards} gridChildren=${r.gridKids} emptyAnchors=${r.emptyAnchors} panelTables=${r.panelTables} errs=${errs.length} → ${ok ? 'PASS' : 'FAIL'}`);
  if (errs.length) console.log('   ' + errs.slice(0, 3).join('\n   '));
  return ok;
}
const a = await run(chromium, 'chromium');
const b = await run(webkit, 'webkit(creds-in-url)');
process.exit(a && b ? 0 : 1);