38 lines
3.6 KiB
JavaScript
38 lines
3.6 KiB
JavaScript
|
|
const assert=require('node:assert/strict')
|
||
|
|
const {chromium}=require('C:/Users/Administrator/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules/playwright')
|
||
|
|
;(async()=>{
|
||
|
|
const login=await(await fetch('http://127.0.0.1:8080/login',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({username:'admin',password:'admin123',code:'',uuid:''})})).json();assert.equal(login.code,200)
|
||
|
|
const browser=await chromium.launch({channel:'chrome',headless:true,args:['--disable-gpu','--js-flags=--max-old-space-size=256']})
|
||
|
|
try{
|
||
|
|
const context=await browser.newContext({viewport:{width:1366,height:768}});await context.addCookies([{name:'Admin-Token',value:login.token,url:'http://127.0.0.1:8088'}]);const page=await context.newPage();const errors=[];page.on('pageerror',e=>errors.push(e.message));let delay=0
|
||
|
|
await page.route('**/dev-api/**',async route=>{const req=route.request(),p=new URL(req.url()).pathname;assert.ok(['GET','HEAD'].includes(req.method()),'No business writes allowed');if(/\/warehouse\/(stock|product|purchase|in)(\/batch)?\/list$/.test(p)){if(delay)await new Promise(r=>setTimeout(r,delay));return route.fulfill({json:{code:200,rows:[],total:0}})}return route.continue()})
|
||
|
|
await page.goto('http://127.0.0.1:8088/index',{waitUntil:'domcontentloaded'});await page.waitForFunction(()=>document.querySelector('.business-home')?.__vue__?.loadedOnce)
|
||
|
|
const reports=[]
|
||
|
|
for(const [path,name] of [['/warehouse/stock','库存'],['/businessBasics/product','物品'],['/procurement/details','采购批次'],['/procurement/arrival','到货']]){
|
||
|
|
for(const wait of [0,600]){
|
||
|
|
delay=wait
|
||
|
|
const frames=await page.evaluate(async({path,wait})=>{
|
||
|
|
const frames=[],until=performance.now()+1350
|
||
|
|
const finished=new Promise(resolve=>{
|
||
|
|
function frame(){requestAnimationFrame(()=>setTimeout(()=>{
|
||
|
|
const root=document.querySelector('.desktop-viewport')?.firstElementChild
|
||
|
|
if(location.pathname===path && root && !root.className.includes('leave')){
|
||
|
|
const table=[...root.querySelectorAll('.el-table')].find(t=>t.__vue__?.$options.name==='ElTable'&&t.getClientRects().length&&!t.closest('.el-dialog,.el-drawer'))
|
||
|
|
if(table){const r=table.getBoundingClientRect();frames.push({height:r.height,top:r.top,animations:root.getAnimations().map(a=>a.transitionProperty||a.animationName||'animation'),transition:getComputedStyle(root).transitionProperty,opacity:Number(getComputedStyle(root).opacity)})}
|
||
|
|
}
|
||
|
|
if(performance.now()<until)frame();else resolve(frames)
|
||
|
|
},0))}frame()
|
||
|
|
})
|
||
|
|
await document.querySelector('#app').__vue__.$router.push(path+'?emptycheck='+wait)
|
||
|
|
return finished
|
||
|
|
},{path,wait})
|
||
|
|
assert.ok(frames.length>5,name+' has no sampled table')
|
||
|
|
const report={page:name,delay:wait,min:Math.round(Math.min(...frames.map(f=>f.height))),max:Math.round(Math.max(...frames.map(f=>f.height))),animations:[...new Set(frames.flatMap(f=>f.animations))],fade:frames.some(f=>f.opacity<1),frames:frames.length}
|
||
|
|
reports.push(report);console.log(JSON.stringify(report))
|
||
|
|
if(!process.env.REPORT_ONLY){assert.ok(report.min>180,name+' short empty table');assert.ok(report.max-report.min<=2,name+' height animation '+JSON.stringify(report));assert.deepEqual(report.animations,[],name+' page animation remains');assert.equal(report.fade,false,name+' page fade remains')}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
assert.deepEqual(errors,[]);console.log(process.env.REPORT_ONLY?'Animation baseline recorded':'PASS: 4 empty list pages, immediate and delayed responses, stable post-frame geometry, no page/flex-size animation. No business writes.')
|
||
|
|
}finally{await browser.close()}
|
||
|
|
})().catch(e=>{console.error(e);process.exitCode=1})
|