perf: optimize full interface loading and refresh paths

This commit is contained in:
abaishu0730 committed 2026-10-28 09:24:04 +08:00
1 parent 649a0df832
commit f317314a3c
57 files changed
+791 -136

No files matched your search

+6 -2
View File
@@ -48,10 +48,11 @@ async function fixture(t,{user={username:'alice',role:'operator'},connections,ac
});
await page.goto(base);
await page.addStyleTag({path:path.join(__dirname,'../../web/app.css')});
await page.addScriptTag({path:path.join(__dirname,'../../web/modules/navigation/lifecycle.js')});
if(fs.existsSync(source))await page.addScriptTag({path:source});
assert.equal(await page.evaluate(()=>typeof window.BpmLogin?.mount),'function','BPM page exposes a working mount function');
await page.evaluate(async user=>{
const api=async(route,body)=>{const r=await fetch('/api'+route,{method:body===undefined?'GET':'POST',headers:{'Content-Type':'application/json'},body:body===undefined?undefined:JSON.stringify(body)});return r.json();};
const api=async(route,body,{signal}={})=>{const r=await fetch('/api'+route,{signal,method:body===undefined?'GET':'POST',headers:{'Content-Type':'application/json'},body:body===undefined?undefined:JSON.stringify(body)});return r.json();};
await window.BpmLogin.mount(document.querySelector('#root'),{api,esc:v=>String(v??'').replaceAll('<','&lt;'),formatDate:v=>v||'—',notify:()=>{},user,isActive:()=>true});
},user);
return {page,calls,releaseOpen,releaseInput,releaseFrame,releaseSave,releaseAccount,releaseFill,releaseAccountSave,maxFrames:()=>maxFrames};
@@ -286,8 +287,9 @@ for(const pendingAction of ['open','save'])test(`document unload sends authentic
const appSource=fs.readFileSync(path.join(__dirname,'../../web/app.js'),'utf8').replace(/boot\(\)\.catch[\s\S]*$/,'');
const fixtureServer=http.createServer(async(req,res)=>{
const requestPath=new URL(req.url,'http://localhost').pathname;
if(requestPath==='/lifecycle.js'){res.setHeader('Content-Type','application/javascript; charset=utf-8');return res.end(fs.readFileSync(path.join(__dirname,'../../web/modules/navigation/lifecycle.js')));}
if(requestPath==='/bpm.js'||requestPath==='/app.js'){res.setHeader('Content-Type','application/javascript; charset=utf-8');return res.end(requestPath==='/bpm.js'?fs.readFileSync(source):appSource);}
if(!requestPath.startsWith('/api/')){res.setHeader('Content-Type','text/html; charset=utf-8');return res.end('<div id="app"></div><div id="root"></div><script src="/bpm.js"></script><script src="/app.js"></script>');}
if(!requestPath.startsWith('/api/')){res.setHeader('Content-Type','text/html; charset=utf-8');return res.end('<div id="app"></div><div id="root"></div><script src="/lifecycle.js"></script><script src="/bpm.js"></script><script src="/app.js"></script>');}
let body='';for await(const chunk of req)body+=chunk;
calls.push({path:requestPath,body,cookie:req.headers.cookie,origin:req.headers.origin});
res.setHeader('Content-Type','application/json');
@@ -364,3 +366,5 @@ test('UI renders backend conclusions without reinterpreting raw connection flags
assert.equal(await f.page.locator('[data-sync-status] .bpm-status-yellow').count(),1);
await f.page.getByText('后端已核实会话',{exact:true}).waitFor();
});
test('remote login frames pause hidden and resume a single frame without replacing the session',async t=>{const f=await fixture(t);await f.page.getByRole('button',{name:'远程登录',exact:true}).click();await f.page.locator('[data-bpm-frame]').waitFor();await f.page.clock.install();const frames=()=>f.calls.filter(c=>c.path.endsWith('/frame')).length,before=frames();await f.page.evaluate(()=>{Object.defineProperty(document,'hidden',{value:true,configurable:true});document.dispatchEvent(new Event('visibilitychange'));});await f.page.clock.fastForward(10001);await delay(100);assert.equal(frames(),before);const response=f.page.waitForResponse(r=>r.url().endsWith('/login/frame'));await f.page.evaluate(()=>{Object.defineProperty(document,'hidden',{value:false,configurable:true});document.dispatchEvent(new Event('visibilitychange'));});await response;assert.equal(frames(),before+1);assert.equal(f.calls.filter(c=>c.path.endsWith('/open')).length,1);assert.equal(f.calls.filter(c=>c.path.endsWith('/close')).length,0);});