| 1234567891011121314151617181920212223242526272829303132 |
- // P76 核验:作用域化门户 CSS + 门户 #cms 节原文(内联 v-html)
- 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.onerror = (m) => console.log('WIN_ERR ' + String(m).slice(0, 160))
- 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 (w.document.querySelector('.portal-cms-scope')) break }
- const root = w.document.querySelector('#root') || w.document.body
- const scope = root.querySelector('.portal-cms-scope')
- const txt = (scope ? scope.textContent : '').replace(/\s+/g, ' ')
- const st = Array.from(root.querySelectorAll('style')).map((s) => s.textContent || '').join('\n')
- console.log('SCOPE ' + (scope ? 'Y' : 'N') + ' ELEMENTS ' + (scope ? scope.querySelectorAll('*').length : 0))
- console.log('SCOPED_CSS ' + /\.portal-cms-scope\s+\.hero/.test(st) + ' ROOT_AS_SCOPE ' + /\.portal-cms-scope\{--ground/.test(st.replace(/\s+/g, '')))
- console.log('HAS_HERO ' + /振动与 SCADA 联合分析/.test(txt) + ' HAS_LEAD ' + /六层模型/.test(txt))
- console.log('HAS_ORIG_ITEMS ' + /TCM 六采集窗|windcms|状态监测/.test(txt))
- console.log('HAS_LIVE ' + (/当前时间窗 · /.test(txt) && /需关注 \d+ 台/.test(txt)))
- console.log('CHIP_CLASS ' + (scope ? scope.querySelectorAll('.chip').length : 0))
|