// Click-everything smoke test (SPEC §13.5, L3) against the inlined demo with an in-memory runtime. // Usage: node packages/db/seed/demo-seed.mjs /tmp/seed && node tools/preview/smoke.mjs "$PWD/dist/demo.html" /tmp/seed // Needs puppeteer-core and a local Chrome (not wired into CI yet; W1-14 replaces this with Playwright). import puppeteer from 'puppeteer-core'; import fs from 'fs'; import path from 'path'; const [file, seedDir] = process.argv.slice(2); const seed = {}; for (const col of fs.readdirSync(seedDir)) for (const f of fs.readdirSync(path.join(seedDir, col))) seed[`${col}/${f.replace('.json', '')}`] = JSON.parse(fs.readFileSync(path.join(seedDir, col, f), 'utf8')); seed['students/u_reviewer'] = { ...seed['students/sample-2'], id: 'u_reviewer', name: 'Kirubel Kibru', isSample: false }; const mock = fs.readFileSync(new URL('./runtime-mock.js', import.meta.url), 'utf8'); const routes = [ ['', 1], ['#/am/signin', 1], ['#/am'], ['#/am/courses'], ['#/en/course/makeup-foundations'], ['#/am/course/bridal-makeup'], ['#/am/learn/makeup-foundations/les-f3'], ['#/am/learn/bridal-makeup/les-b4'], ['#/am/checkout/bridal-makeup'], ['#/am/my'], ['#/am/progress'], ['#/am/notifications'], ['#/am/help'], ['#/am/profile'], ]; const b = await puppeteer.launch({ executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', headless: true }); const problems = []; let clicks = 0; async function open(p, hash, signedOut) { await p.goto('about:blank'); // The app rewrites the hash while booting, and Puppeteer sometimes misses that load's lifecycle event and // waits forever. If the document did load, carry on; if it didn't, fail as before. await p.goto('file://' + file + hash, { waitUntil: 'domcontentloaded', timeout: 15000 }) .catch(async (e) => { if ((await p.evaluate(() => document.readyState).catch(() => '')) === 'loading' || !(await p.evaluate(() => !!document.body).catch(() => false))) throw e; }); await new Promise((r) => setTimeout(r, 500)); } async function worker(list) { const p = await b.newPage(); await p.setViewport({ width: 1280, height: 900 }); let errs = []; p.on('pageerror', (e) => errs.push(e.message)); // Offline run: block third-party requests (the Vimeo placeholder iframe can stall unloading the player page). await p.setRequestInterception(true); p.on('request', (r) => (/^(file|data|about|blob):/.test(r.url()) || /fonts\.(googleapis|gstatic)\.com/.test(r.url()) ? r.continue() : r.abort())); await p.evaluateOnNewDocument((s) => { window.__SEED__ = s; }, seed); await p.evaluateOnNewDocument(mock); await p.evaluateOnNewDocument(() => { try { localStorage.setItem('lms.langChosen', '1'); localStorage.setItem('lms.tourDone', '1'); } catch {} }); for (const [hash, signedOut] of list) { await p.evaluateOnNewDocument((so) => { try { so ? localStorage.setItem('lms.signedOut', '1') : localStorage.removeItem('lms.signedOut'); } catch {} }, !!signedOut); await open(p, hash, signedOut); if (errs.length) { problems.push(`${hash} LOAD ERROR ${errs}`); errs = []; } const main = await p.evaluate(() => (document.querySelector('main')?.innerText ?? '').trim().length); if (main < 20) problems.push(`${hash} blank main region`); const n = await p.evaluate(() => [...document.querySelectorAll('button, a[href^="#"]')].filter((e) => e.offsetParent && !e.disabled).length); for (let i = 0; i < Math.min(n, 60); i++) { await open(p, hash, signedOut); errs = []; const res = await p.evaluate(async (i) => { const els = [...document.querySelectorAll('button, a[href^="#"]')].filter((e) => e.offsetParent && !e.disabled); const el = els[i]; if (!el) return null; const label = (el.getAttribute('aria-label') || el.innerText || '').trim().slice(0, 40); if (/feedback|አስተያየት/i.test(label) || el.closest('.s-tabs')) return { label, skip: true }; const before = document.body.innerHTML.length + location.hash + document.body.innerText; el.click(); await new Promise((r) => setTimeout(r, 350)); const after = document.body.innerHTML.length + location.hash + document.body.innerText; return { label, changed: before !== after }; }, i); clicks++; if (!res || res.skip) continue; if (errs.length) problems.push(`${hash} [${res.label}] ERROR ${errs[0]}`); else if (!res.changed) problems.push(`${hash} [${res.label}] no visible change`); } } await p.close(); } const chunks = [[], [], [], []]; routes.forEach((r, i) => chunks[i % 4].push(r)); await Promise.all(chunks.map(worker)); await b.close(); console.log(`clicked ${clicks} controls on ${routes.length} routes`); console.log(problems.length ? problems.join('\n') : 'no problems');