| 123456789101112131415161718192021222324252627282930313233343536 |
- 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')
- // ① 门户导航
- let shell = readFileSync(dist + '/portal/shell.html', 'utf8')
- const ids = Array.from(shell.matchAll(/<!--@TEMPLATE:([^>]+?)-->/g)).map((m) => m[1])
- for (const id of ids) shell = shell.replace('<!--@TEMPLATE:' + id + '-->', '<template id="' + id + '"></template>')
- for (const id2 of ['cms', 'documents', 'recalc']) shell = shell.replace(new RegExp('<a[^>]*data-nav="' + id2 + '"[^>]*>[^<]*</a>', 'g'), '')
- console.log('NAV_CMS ' + /data-nav="cms"/.test(shell) + ' NAV_DOCS ' + /data-nav="documents"/.test(shell) + ' NAV_RECALC ' + /data-nav="recalc"/.test(shell))
- // ② 振动 CMS(Shadow DOM)
- 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 (w.document.querySelector('[data-fsub-host]')) break }
- const host = w.document.querySelector('[data-fsub-host]')
- const sr = host && host.shadowRoot
- const inner = sr ? sr.innerHTML : ''
- console.log('HOST ' + (host ? 'Y' : 'N') + ' SHADOW ' + (sr ? 'Y' : 'N') + ' LEN ' + inner.length)
- console.log('HAS_PORTAL_CSS ' + /--ground|\.hero/.test(inner))
- console.log('HAS_HERO_TITLE ' + /振动与 SCADA 联合分析/.test(inner))
- console.log('HAS_CHIPS ' + /<div class="chips">/.test(inner) + ' CHIP_COUNT ' + (inner.match(/class="chip/g) || []).length)
- console.log('HAS_LIVE_WIN ' + /当前时间窗 · /.test(inner))
|