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 dom = new JSDOM(idx.replace('', ''), { url: 'http://127.0.0.1:28084/detail/v2#tab=system', 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 : '{}' 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, 100)) } for (let i = 0; i < 20; i++) { await new Promise((r) => setTimeout(r, 400)); if (w.document.querySelector('[data-added="recalc"]')) break } const d = w.document const blk = d.querySelector('[data-added="recalc"]') const chip = blk && blk.querySelector('.chip') const hero = blk && blk.querySelector('.hero') const cs = (el) => el ? w.getComputedStyle(el) : null const c1 = cs(chip), h1 = cs(hero) console.log('CHIP_STYLE ' + (c1 ? ('radius=' + c1.borderRadius + ' bg=' + c1.backgroundColor + ' disp=' + c1.display) : '无')) console.log('HERO_STYLE ' + (h1 ? ('bg=' + h1.backgroundColor + ' pad=' + h1.padding) : '无')) console.log('PORTAL_CSS_PRESENT ' + /--ground|\.hero\{|\.chip/.test(css))