_check_conf_panel.mjs 2.0 KB

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