test(service-worker): add helper function remove individual cache (#36847)

This commit adds a helper method to remove individual cached items.

PR Close #36847
This commit is contained in:
Sonu Kapoor 2020-07-31 08:40:48 -04:00 committed by Joey Perrott
parent 0a7a5e3aff
commit 38d6596742
1 changed files with 10 additions and 0 deletions

View File

@ -1762,6 +1762,16 @@ describe('Driver', () => {
});
})();
async function removeAssetFromCache(
scope: SwTestHarness, appVersionManifest: Manifest, assetPath: string) {
const assetGroupName =
appVersionManifest.assetGroups?.find(group => group.urls.includes(assetPath))?.name;
const cacheName = `${scope.cacheNamePrefix}:${sha1(JSON.stringify(appVersionManifest))}:assets:${
assetGroupName}:cache`;
const cache = await scope.caches.open(cacheName);
return cache.delete(assetPath);
}
async function makeRequest(
scope: SwTestHarness, url: string, clientId: string|null = 'default',
init?: Object): Promise<string|null> {