cmvr-wms/scripts/projectdev/vue3-migration-check.cjs

27 lines
3.1 KiB
JavaScript
Raw Permalink Normal View History

const assert=require('node:assert/strict'),fs=require('node:fs'),path=require('node:path')
const {chromium}=require('./vue3-test-runtime.cjs')
const base=process.env.VUE3_URL||'http://127.0.0.1:8088'
;(async()=>{
const login=await(await fetch((process.env.BACKEND_URL || 'http://127.0.0.1:8080') + '/login',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({username: process.env.TEST_USERNAME || 'admin',password: process.env.TEST_PASSWORD || 'admin123',code:'',uuid:''})})).json();assert.equal(login.code,200)
const menu=await(await fetch((process.env.BACKEND_URL || 'http://127.0.0.1:8080') + '/getRouters',{headers:{Authorization:'Bearer '+login.token}})).json(),routes=[]
function collect(nodes,parent=''){for(const r of nodes||[]){const url=r.path.startsWith('/')?r.path:(parent+'/'+r.path).replace(/\/+/g,'/');if(r.children?.length)collect(r.children,url);else if(r.component&&!r.hidden&&!/^https?:/.test(url))routes.push({url,title:r.meta?.title})}}
collect(menu.data)
const browser=await chromium.launch({headless:true,args:['--disable-gpu']})
const out=path.resolve(__dirname,'../../.codex-tmp/vue3-migration-check');fs.mkdirSync(out,{recursive:true})
try{
const context=await browser.newContext({viewport:{width:1440,height:900}});await context.addCookies([{name:'Admin-Token',value:login.token,url:base}]);const page=await context.newPage();page.setDefaultTimeout(12000)
const errors=[],httpErrors=[],warnings=[]
page.on('pageerror',e=>{errors.push({url:page.url(),error:e.message});console.log('ERROR',e.message)})
page.on('console',m=>{if(m.type()==='warning'&&/Failed to resolve|Invalid prop|Unhandled error|was accessed during render/.test(m.text()))warnings.push({url:page.url(),message:m.text()})})
page.on('response',r=>{if(r.status()>=400)httpErrors.push({url:r.url(),status:r.status()})})
await page.route('**/dev-api/**',r=>['GET','HEAD'].includes(r.request().method())?r.continue():r.abort('blockedbyclient'))
await page.goto(base+'/index',{waitUntil:'domcontentloaded'});await page.locator('.business-home').waitFor();await page.waitForTimeout(700)
assert.equal(await page.locator('.home-todo').count(),5)
await page.screenshot({path:path.join(out,'home.png')})
for(const r of routes){await page.goto(base+r.url,{waitUntil:'domcontentloaded'});await page.locator('.desktop-viewport').waitFor();await page.waitForTimeout(400);await page.waitForFunction(()=>![...document.querySelectorAll('.desktop-viewport .el-loading-mask')].some(e=>e.getClientRects().length),null,{timeout:12000});console.log('CHECK',r.title,r.url);if(!['/monitor/druid','/tool/swagger'].includes(r.url))assert.equal(await page.locator('.error-page').count(),0,r.url);await page.screenshot({path:path.join(out,r.url.replace(/[^a-zA-Z0-9]/g,'_')+'.png')})}
fs.writeFileSync(path.join(out,'result.json'),JSON.stringify({routes,errors,httpErrors,warnings},null,2))
console.log('RESULT',JSON.stringify({pages:routes.length,errors,httpErrors,warnings:warnings.slice(0,20),warningCount:warnings.length}))
assert.deepEqual(errors,[]);assert.deepEqual(httpErrors,[])
}finally{await browser.close()}
})().catch(e=>{console.error(e);process.exitCode=1})