_check_portal.mjs 1.4 KB

123456789101112131415161718192021222324
  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="\.\/assets\/([^"]+\.js)"/) || [])[1]
  9. const cssFile = (idx.match(/href="\.\/assets\/([^"]+\.css)"/) || [])[1]
  10. const code = readFileSync(dist + '/assets/' + jsFile, 'utf8')
  11. const css = readFileSync(dist + '/assets/' + cssFile, 'utf8')
  12. const dom = new JSDOM(idx.replace('</head>', '<style>' + css + '</style></head>'),
  13. { url: 'http://127.0.0.1:28084/', runScripts: 'outside-only', pretendToBeVisual: true, virtualConsole: new VirtualConsole() })
  14. const w = dom.window
  15. w.fetch = async (u) => ({ ok: true, status: 200, json: async () => ({}), text: async () => '<html><head><title>观澜中文系统 · 详细分析</title></head><body><div class="wrap">门户</div></body></html>' })
  16. try { w.eval(code) } catch (e) { console.log('EVAL_ERR ' + String(e).slice(0, 120)) }
  17. await new Promise((r) => setTimeout(r, 1500))
  18. const d = w.document
  19. console.log('PORTAL_MODE ' + !!d.querySelector('.portal-full'))
  20. console.log('TITLE ' + d.title)
  21. const fr = d.querySelector('iframe.portal-frame')
  22. console.log('IFRAME ' + (fr ? 'ok' : '缺失'))
  23. console.log('HAS_WORKBENCH_WRAP ' + !!d.querySelector('.wrap'))