@davoodmehraban89 / VELYQOR / commits / 76e2eaa
Fork 0

Intelligence, Advanced Charting & Trading Platform

test(incident): ensure mocked origin network actually fails before testing SW offline fallback

davoodmehraban89 committed Oct 15, 2026 at 19:42 UTC 76e2eaa654fd04a510229221ddb971156cc92035
1 file changed +4 -1
scripts/diagnose-chartnova-v27-sw-cache.mjs
+4 -1
@@ -22,7 +22,8 @@ const report={scenario:'actual_v27_service_worker_offline_and_artificial_poison'
22 try{
23 const ctx=await browser.newContext({viewport:{width:390,height:844},isMobile:true,serviceWorkers:'allow'});
24 await ctx.route('**/api/**',r=>r.fulfill({status:503,contentType:'application/json',body:'{"ok":false,"error":"STAGING_ONLY"}'}));
25 - await ctx.route(host,r=>r.fulfill({status:200,contentType:'text/html; charset=utf-8',body:html}));
25 + let simulateOffline=false;
26 + await ctx.route(host,r=>simulateOffline?r.abort('internetdisconnected'):r.fulfill({status:200,contentType:'text/html; charset=utf-8',body:html}));
27 await ctx.route('**/sw.js',r=>r.fulfill({status:200,contentType:'application/javascript',body:sw}));
28 // Cache installation assets; no request to production and no provider/DB mutation.
29 await ctx.route('**/icon.svg',r=>r.fulfill({status:200,contentType:'image/svg+xml',body:'<svg xmlns="http://www.w3.org/2000/svg"/>'}));
@@ -33,6 +34,7 @@ try{
34 await page.goto(host,{waitUntil:'domcontentloaded',timeout:20000});
35 await page.waitForFunction(()=>!!navigator.serviceWorker?.controller,undefined,{timeout:12000});
36 await page.waitForFunction(async()=> (await caches.keys()).includes('chartnova-v1'),undefined,{timeout:12000});
37 + simulateOffline=true;
38 await ctx.setOffline(true);
39 await page.reload({waitUntil:'domcontentloaded',timeout:16000});
40 report.validCachedOfflineVisible=await page.evaluate(()=>!!document.querySelector('.shell')&&
@@ -47,6 +49,7 @@ try{
49 document.title==='TEST-CORRUPT'&&!document.querySelector('.shell')&&
50 (document.body?.innerText.length??0)===0);
51 await ctx.setOffline(false);
52 + simulateOffline=false;
53 await page.reload({waitUntil:'domcontentloaded',timeout:16000});
54 report.onlineRecoveredVisible=await page.evaluate(()=>
55 !!document.querySelector('.shell')&&document.querySelector('.shell').getBoundingClientRect().width>80);