| 1234567891011121314151617181920212223242526 |
- 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 calls = []
- const dom = new JSDOM(idx.replace('</head>', '<style>' + css + '</style></head>'),
- { 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); calls.push(s)
- 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, 120)) }
- for (let i = 0; i < 24; i++) { await new Promise((r) => setTimeout(r, 400)); if (calls.some((x) => /maint_survey/.test(x))) break }
- await new Promise((r) => setTimeout(r, 1500))
- console.log('CALLS ' + JSON.stringify(calls))
- console.log('MAINT_CALLED ' + calls.some((x) => /maint_survey/.test(x)))
- console.log('TABS_ACTIVE ' + (Array.from(w.document.querySelectorAll('nav.tabs#tabs > button')).find((b) => String(b.className).includes('on')) || {}).textContent)
|