Resume offline preparation on launch and show cache readiness

This commit is contained in:
Jonathan Sykes
2026-10-09 09:33:23 +08:00
parent 0251720fa2
commit 009a155568
6 changed files with 63 additions and 8 deletions

View File

@@ -368,3 +368,22 @@ test('an unanswered worker status cannot fall through to an empty legacy refresh
vm.runInNewContext(fs.readFileSync(__dirname+'/sw-update.js','utf8'),sandbox);
await assert.rejects(sandbox.SwUpdate.refreshShellInPlace({cachesApi:{open:async()=>({}),keys:async()=>[]},fetchFn:async()=>({ok:true,json:async()=>({buildTag:'new'})}),isShellCache:()=>true}),/Worker update status unavailable/);
});
test('update readiness retains completion progress without blocking the ready fast path',async()=>{
const phases=[],container=fakeContainer();let downloaded=false;
const status={ready:true,offlineReady:false,cached:90,total:151,missingFiles:['/optional.js']};
await applyUpdate({reg:{waiting:{postMessage(){}}},container,askStatus:async()=>status,
onPhase:(phase,progress)=>phases.push({phase,progress}),refreshShell:async()=>{downloaded=true;},setTimeout:()=>{}});
assert.equal(downloaded,false);assert.equal(phases[0].phase,'ready');assert.deepStrictEqual(phases[0].progress,status);
});
test('offline cache status reports preparing and complete counts in Settings',()=>{
const vm=require('node:vm'),fs=require('node:fs'),element={};
const sandbox={document:{getElementById:()=>element}};
vm.runInNewContext(fs.readFileSync(__dirname+'/sw-update.js','utf8'),sandbox);
sandbox.SwUpdate.showOfflineStatus({offlineReady:false,cached:90,total:151});
assert.equal(element.textContent,'Preparing offline 90/151');
sandbox.SwUpdate.showOfflineStatus({offlineReady:true,cached:151,total:151});
assert.equal(element.textContent,'Offline ready 151/151');
sandbox.SwUpdate.showOfflineStatus({ready:true});assert.equal(element.textContent,'Offline ready (legacy cache)');
});