browser.mjs (1505B)
1 // Démarrage : ouvre l'URL, attend `secondes`, vérifie que le module WebAssembly a chargé et que le 2 // canevas SDL est affiché, puis enregistre une capture d'écran. Échoue si la VM n'a pas démarré. 3 // node test/browser.mjs [url] [secondes] [capture.png] 4 import { open, sleep } from './cdp.mjs'; 5 6 const url = process.argv[2] ?? 'http://localhost:8083/'; 7 const secs = Number(process.argv[3] ?? 14); 8 const shot = process.argv[4] ?? '/tmp/exl100.png'; 9 10 const page = await open(url, { width: 900, height: 1100 }); 11 await sleep(secs * 1000); 12 13 const state = await page.evaluate(`(() => { 14 const c = document.getElementById('canvas'); 15 const st = document.getElementById('status'); 16 return { 17 hasModule: typeof window.Module === 'object', 18 canvasShown: c ? getComputedStyle(c).display !== 'none' : false, 19 canvasW: c ? c.width : 0, 20 canvasH: c ? c.height : 0, 21 status: st ? st.textContent.trim() : '(pas de #status)', 22 }; 23 })()`); 24 console.log('Module WASM :', state.hasModule); 25 console.log('Canevas affiché :', state.canvasShown, `(${state.canvasW}x${state.canvasH})`); 26 console.log('Statut :', state.status); 27 for (const l of page.logs) console.log(l); 28 console.log('Capture :', await page.screenshot(shot)); 29 page.close(); 30 31 const errored = page.logs.some((l) => /abort|uncaught|exception|cannot load|BIOS/i.test(l)); 32 if (!state.hasModule || !state.canvasShown || state.canvasW < 2 || errored) { 33 console.error('ÉCHEC : la machine n’a pas démarré proprement'); 34 process.exit(1); 35 }