import { readFileSync } from 'node:fs' import { fileURLToPath } from 'node:url' import { dirname, resolve } from 'node:path' import { JSDOM, VirtualConsole } from 'jsdom' const HERE = dirname(fileURLToPath(import.meta.url)) const dist = resolve(HERE, '../../../release/web') const GW = 'http://106.120.102.238:28084' const fleet = await (await fetch(GW + '/api/fleet?ts=' + Date.now())).text() const idx = readFileSync(dist + '/index.html', 'utf8') const jsFile = (idx.match(/src="([^"]+\.js)"/) || [])[1].replace(/^.*\//, '') const cssFile = (idx.match(/href="([^"]+\.css)"/) || [])[1].replace(/^.*\//, '') const code = readFileSync(dist + '/assets/' + jsFile, 'utf8') const css = readFileSync(dist + '/assets/' + cssFile, 'utf8') const errs = [] const vc = new VirtualConsole() vc.on('jsdomError', (e) => errs.push(String(e && e.message).slice(0, 110))) const dom = new JSDOM(idx.replace('', ''), { url: GW + '/detail/v2#tab=vibration', runScripts: 'outside-only', pretendToBeVisual: true, virtualConsole: vc }) const w = dom.window w.fetch = async (u) => { const s = String(u); const b = /fleet/.test(s) ? fleet : '{}' return { ok: true, status: 200, json: async () => JSON.parse(b), text: async () => b } } try { w.eval(code) } catch (e) { errs.push('EVAL ' + String(e).slice(0, 120)) } for (let i = 0; i < 30; i++) { await new Promise((r) => setTimeout(r, 400)); if (w.document.querySelector('[data-added="hysteresis"]')) break } const p = w.document.querySelector('[data-added="hysteresis"]') console.log('HYST_PANEL ' + !!p) if (p) console.log('TEXT ' + JSON.stringify((p.textContent || '').replace(/\s+/g, ' ').trim().slice(0, 260))) const c = w.document.querySelector('[data-added="confidence"]') console.log('CONF_PANEL ' + !!c) console.log('ERRS ' + errs.length + (errs.length ? ' :: ' + errs[0] : ''))