Skip to content

Commit

Permalink
chore: make testing easier by guaranteeing precaching failures
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiVandivier committed Aug 3, 2023
1 parent be95c41 commit 5341289
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions pwa/src/service-worker/set-up-service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,16 @@ export function setUpServiceWorker() {
const sharedBuildManifest = self.__WB_BUILD_MANIFEST || []
precacheAndRoute(sharedBuildManifest)
} else {
// Test these by using the "Network request blocking" dev tools to cause errors
// This will execute in dev environments
precacheAndRoute([
// Let this one work
{ url: './index.html', revision: '1' },
// Set one or more of the following to fail
{ url: './hey.jpg', revision: '1' },
{ url: './bogus1.jpg', revision: '1' },
{ url: './derp2.jpg', revision: '1' },
{ url: './diddlibap3.jpg', revision: '1' },
{ url: './squip4.jpg', revision: '1' },
// The following are expected to fail
{ url: 'https://not-a-site.com/hey.jpg', revision: '1' },
{ url: 'https://not-a-site.com/bogus1.jpg', revision: '1' },
{ url: 'https://not-a-site.com/derp2.jpg', revision: '1' },
{ url: 'https://not-a-site.com/diddlibap3.jpg', revision: '1' },
{ url: 'https://not-a-site.com/squip4.jpg', revision: '1' },
])

/* An alternative to patch package, where a custom precache controller is made and implemented
Expand Down Expand Up @@ -212,12 +212,12 @@ export function setUpServiceWorker() {
const precacheController = new CustomPrecacheController()
precacheController.addToCacheList([
{ url: './index.html', revision: '5' },
{ url: './hey.jpg', revision: '1000' },
{ url: './bogus1.jpg', revision: '1000' },
{ url: './derp2.jpg', revision: '1000' },
{ url: './diddlibap3.jpg', revision: '1000' },
{ url: './squip4.jpg', revision: '1000' },
{ url: 'https://not-a-site.com/index.html', revision: '5' },
{ url: 'https://not-a-site.com/hey.jpg', revision: '1000' },
{ url: 'https://not-a-site.com/bogus1.jpg', revision: '1000' },
{ url: 'https://not-a-site.com/derp2.jpg', revision: '1000' },
{ url: 'https://not-a-site.com/diddlibap3.jpg', revision: '1000' },
{ url: 'https://not-a-site.com/squip4.jpg', revision: '1000' },
])
self.addEventListener('install', (event) => {
Expand Down

0 comments on commit 5341289

Please sign in to comment.