kopia lustrzana https://gitlab.com/rysiekpl/libresilient
working on tests for the improved config.json handling (ref. #48)
rodzic
0fe53bcc20
commit
28c79a35e4
|
@ -111,7 +111,7 @@ beforeAll(async ()=>{
|
|||
*/
|
||||
window.registration = {
|
||||
scope: "https://test.resilient.is/",
|
||||
unregister: ()=>{}
|
||||
unregister: spy(()=>{})
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -370,6 +370,20 @@ describe('service-worker', async () => {
|
|||
assertSpyCalls(self.fetch, 1)
|
||||
})
|
||||
|
||||
it("should throw a meaningful exception when an unhandled exception occurs during initialization", async () => {
|
||||
|
||||
// this will generate an exception on line where a new Map()
|
||||
// is created from self.LibResilientPluginConstructors
|
||||
self.LibResilientPluginConstructors = true
|
||||
|
||||
await import("../../service-worker.js?" + window.test_id);
|
||||
|
||||
// the a failed install event handler in the service worker code
|
||||
// will run self.registration.unregister() to not leave the site in a broken state
|
||||
await self.dispatchEvent(new Event('install'))
|
||||
assertSpyCalls(self.registration.unregister, 1)
|
||||
})
|
||||
|
||||
it("should use default LibResilientConfig values when fetching config.json throws an exception", async () => {
|
||||
|
||||
window.fetch = spy(() => {
|
||||
|
|
|
@ -641,7 +641,7 @@ let initServiceWorker = async () => {
|
|||
// we got an error while initializing the service worker!
|
||||
// better play it safe!
|
||||
self.registration.unregister()
|
||||
throw e
|
||||
return false
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -1131,11 +1131,12 @@ let getResourceThroughLibResilient = (url, init, clientId, useStashed=true, doSt
|
|||
|* === Setting up the event handlers === *|
|
||||
\* ========================================================================= */
|
||||
self.addEventListener('install', async (event) => {
|
||||
await event.waitUntil(
|
||||
initServiceWorker()
|
||||
)
|
||||
// "COMMIT_UNKNOWN" will be replaced with commit ID
|
||||
self.log('service-worker', "0. Installed LibResilient Service Worker (commit: COMMIT_UNKNOWN).");
|
||||
let init_promise = initServiceWorker()
|
||||
await event.waitUntil(init_promise)
|
||||
if (await init_promise === true) {
|
||||
// "COMMIT_UNKNOWN" will be replaced with commit ID
|
||||
self.log('service-worker', "0. Installed LibResilient Service Worker (commit: COMMIT_UNKNOWN).");
|
||||
}
|
||||
});
|
||||
|
||||
self.addEventListener('activate', async event => {
|
||||
|
|
Ładowanie…
Reference in New Issue