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