|
|
@@ -0,0 +1,28 @@
|
|
|
+
|
|
|
+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 vib = readFileSync(resolve(HERE, '_vibcms_fixture.json'), 'utf8')
|
|
|
+const survey = readFileSync(resolve(HERE, '_survey_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
|
|
|
+const blobs = []
|
|
|
+const origCreate = w.URL.createObjectURL
|
|
|
+w.URL.createObjectURL = (b) => { blobs.push(b); return origCreate ? origCreate(b) : 'blob:stub/' + blobs.length }
|
|
|
+w.fetch = async (u) => { const s = String(u); const body = /fleet/.test(s) ? fleet : (/vibcms/.test(s) ? vib : (/maint_survey/.test(s) ? survey : '{}'))
|
|
|
+ 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 < 20; i++) { await new Promise((r) => setTimeout(r, 400)); if (w.document.querySelector('.portal-cms-frame')) break }
|
|
|
+const f = w.document.querySelector('.portal-cms-frame')
|
|
|
+console.log('FRAME ' + (f ? 'Y' : 'N') + ' SRC ' + (f ? String(f.getAttribute('src')).slice(0, 22) : '-'))
|
|
|
+console.log('BLOBS ' + blobs.length)
|