_check_hyst_panel.mjs 1.8 KB

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