_check_cms_inline.mjs 2.0 KB

12345678910111213141516171819202122232425262728
  1. // P75 核验:「振动 CMS」走与其它子选项卡相同的 v-html 路径,内容应出现在 #root
  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 idx = readFileSync(dist + '/index.html', 'utf8')
  9. const jsFile = (idx.match(/src="([^"]+\.js)"/) || [])[1].replace(/^.*\//, '')
  10. const cssFile = (idx.match(/href="([^"]+\.css)"/) || [])[1].replace(/^.*\//, '')
  11. const code = readFileSync(dist + '/assets/' + jsFile, 'utf8')
  12. const css = readFileSync(dist + '/assets/' + cssFile, 'utf8')
  13. const fleet = readFileSync(resolve(HERE, '_fleet_fixture.json'), 'utf8')
  14. const vib = readFileSync(resolve(HERE, '_vibcms_fixture.json'), 'utf8')
  15. const dom = new JSDOM(idx.replace('</head>', '<style>' + css + '</style></head>'),
  16. { url: 'http://127.0.0.1:28084/detail/v2#tab=vibration:portal_cms', runScripts: 'outside-only', pretendToBeVisual: true, virtualConsole: new VirtualConsole() })
  17. const w = dom.window
  18. w.fetch = async (u) => { const s = String(u); const body = /fleet/.test(s) ? fleet : (/vibcms/.test(s) ? vib : '{}')
  19. return { ok: true, status: 200, json: async () => JSON.parse(body), text: async () => body } }
  20. try { w.eval(code) } catch (e) { console.log('EVAL_ERR ' + String(e).slice(0, 140)) }
  21. for (let i = 0; i < 20; i++) { await new Promise((r) => setTimeout(r, 400)); if (/振动与 SCADA/.test(w.document.body.textContent || '')) break }
  22. const root = w.document.querySelector('#root') || w.document.body
  23. const txt = (root.textContent || '').replace(/\s+/g, ' ')
  24. console.log('ELEMENTS ' + root.querySelectorAll('*').length)
  25. console.log('HAS_TITLE ' + /振动与 SCADA 联合分析/.test(txt))
  26. console.log('HAS_LIVE ' + (/当前时间窗 · /.test(txt) && /需关注 \d+ 台/.test(txt)))
  27. console.log('CHIPS ' + root.querySelectorAll('span[style*="border-radius:999px"]').length)
  28. console.log('HEAD ' + txt.slice(0, 220))