Stage legacy asset migration before activation
This commit is contained in:
@@ -57,6 +57,31 @@ test('waiting status does not start completion and activation delegates it to it
|
||||
assert.equal((await core.status(e.m,cache)).offlineReady,true);
|
||||
});
|
||||
|
||||
test('legacy shell verification is staged during install so Refresh UI activation does no hashing',async()=>{
|
||||
const e=environment(),legacy=await e.storage.open('ytplayer-production-old');let digests=0;
|
||||
await legacy.put('/app.js',new Response('legacy app bytes'));
|
||||
const subtle=e.sandbox.crypto.subtle;
|
||||
e.sandbox.crypto={subtle:{digest:async(...args)=>{digests++;return subtle.digest(...args);}}};
|
||||
await e.dispatch('install');
|
||||
const stagedDigests=digests,cache=await e.storage.open(core.CACHE),candidate=await(await cache.match('/__ytp_candidate/next')).json();
|
||||
assert.ok(stagedDigests>0,'install verified old cached bytes before offering Refresh UI');
|
||||
assert.deepEqual(candidate.legacyCacheNames,['ytplayer-production-old']);
|
||||
assert.ok((await core.state(cache)).current.legacyURLs['/app.js']);
|
||||
await e.dispatch('activate');
|
||||
assert.equal(digests,stagedDigests,'the user-triggered activation does not hash the old shell again');
|
||||
assert.equal((await e.storage.keys()).includes('ytplayer-production-old'),false,'old shell is deleted only after commit');
|
||||
});
|
||||
|
||||
test('offline opt-in is persisted and adds only declared optional groups to completion',async()=>{
|
||||
const e=environment();e.m.files['/large.wasm']={h:'wasm'};e.m.groups.dsp={files:['/large.wasm'],contract:1,background:true,offlineOptIn:'jamesDsp'};
|
||||
await e.dispatch('install');await e.dispatch('activate');await e.complete();
|
||||
const cache=await e.storage.open(core.CACHE);assert.equal(await cache.match('/large.wasm?v=wasm'),undefined);
|
||||
await e.dispatch('message',{data:{type:'OFFLINE_OPT_INS',values:['jamesDsp','not-a-valid-opt-in']}});
|
||||
assert.deepEqual(await core.readOptIns(cache),['jamesDsp']);
|
||||
assert.equal((await cache.match('/large.wasm?v=wasm')).headers.get('X-Asset-Hash'),'wasm');
|
||||
const status=await core.status(e.m,cache);assert.equal(status.offlineReady,true);assert.equal(status.total,3);
|
||||
});
|
||||
|
||||
test('page-captured app is reused on first install without a worker download',async()=>{
|
||||
const e=environment(),cache=await e.storage.open(core.CACHE);
|
||||
await cache.put('/app.js?v=app',new Response('page captured app',{headers:{'X-Asset-Hash':'app'}}));
|
||||
|
||||
Reference in New Issue
Block a user