service-worker: test for all plugins failing added (ref. #8)

merge-requests/3/merge
Michał 'rysiek' Woźniak 2021-09-04 20:45:03 +00:00
rodzic 65965075f0
commit 7588cad783
1 zmienionych plików z 25 dodań i 1 usunięć

Wyświetl plik

@ -144,7 +144,6 @@ describe("service-worker", () => {
})
require("../service-worker.js");
var response = await self.trigger('fetch', new Request('/test.json', {method: "POST"}))
console.log(response)
expect(response.method).toEqual('POST')
expect(await response.json()).toEqual({ test: "success" })
})
@ -367,4 +366,29 @@ describe("service-worker", () => {
expect(self.LibResilientConfig.plugins['dependency1-test'].indirect).toEqual(true)
expect(self.LibResilientConfig.plugins['dependency2-test'].indirect).toEqual(true)
})
test("should error out if all plugins fail", async () => {
self.LibResilientConfig = {
plugins: {
'reject-all': {}
},
loggedComponents: [
'service-worker'
]
}
self.LibResilientPlugins.push({
name: 'reject-all',
description: 'Reject all requests.',
version: '0.0.1',
fetch: (request, init)=>{ return Promise.reject(request); }
})
require("../service-worker.js");
expect.assertions(1)
try {
await self.trigger('fetch', new Request('/test.json', {method: "GET"}))
} catch(e) {
expect(e).toEqual(self.location.origin + '/test.json')
}
})
});