_check_recalc_style.mjs 1.9 KB

1234567891011121314151617181920212223242526272829
  1. import { readFileSync } from 'node:fs'
  2. import { fileURLToPath } from 'node:url'
  3. import { dirname, resolve } from 'node:path'
  4. import { JSDOM, VirtualConsole } from 'jsdom'
  5. const HERE = dirname(fileURLToPath(import.meta.url))
  6. const dist = resolve(HERE, '../../../release/web')
  7. const idx = readFileSync(dist + '/index.html', 'utf8')
  8. const jsFile = (idx.match(/src="([^"]+\.js)"/) || [])[1].replace(/^.*\//, '')
  9. const cssFile = (idx.match(/href="([^"]+\.css)"/) || [])[1].replace(/^.*\//, '')
  10. const code = readFileSync(dist + '/assets/' + jsFile, 'utf8')
  11. const css = readFileSync(dist + '/assets/' + cssFile, 'utf8')
  12. const fleet = readFileSync(resolve(HERE, '_fleet_fixture.json'), 'utf8')
  13. const dom = new JSDOM(idx.replace('</head>', '<style>' + css + '</style></head>'),
  14. { url: 'http://127.0.0.1:28084/detail/v2#tab=system', runScripts: 'outside-only', pretendToBeVisual: true, virtualConsole: new VirtualConsole() })
  15. const w = dom.window
  16. w.fetch = async (u) => { const s = String(u); const body = /fleet/.test(s) ? fleet : '{}'
  17. return { ok: true, status: 200, json: async () => JSON.parse(body), text: async () => body } }
  18. try { w.eval(code) } catch (e) { console.log('EVAL_ERR ' + String(e).slice(0, 100)) }
  19. for (let i = 0; i < 20; i++) { await new Promise((r) => setTimeout(r, 400)); if (w.document.querySelector('[data-added="recalc"]')) break }
  20. const d = w.document
  21. const blk = d.querySelector('[data-added="recalc"]')
  22. const chip = blk && blk.querySelector('.chip')
  23. const hero = blk && blk.querySelector('.hero')
  24. const cs = (el) => el ? w.getComputedStyle(el) : null
  25. const c1 = cs(chip), h1 = cs(hero)
  26. console.log('CHIP_STYLE ' + (c1 ? ('radius=' + c1.borderRadius + ' bg=' + c1.backgroundColor + ' disp=' + c1.display) : '无'))
  27. console.log('HERO_STYLE ' + (h1 ? ('bg=' + h1.backgroundColor + ' pad=' + h1.padding) : '无'))
  28. console.log('PORTAL_CSS_PRESENT ' + /--ground|\.hero\{|\.chip/.test(css))