kopia lustrzana https://gitlab.com/rysiekpl/libresilient
test for SW caching a successfully fetched config.json (ref. #31)
rodzic
99810d3a79
commit
e7ef3bfade
|
@ -293,6 +293,51 @@ describe("service-worker", () => {
|
||||||
expect(self.LibResilientConfig.loggedComponents).toStrictEqual(['service-worker', 'cache'])
|
expect(self.LibResilientConfig.loggedComponents).toStrictEqual(['service-worker', 'cache'])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("basic set-up: a valid config.json file gets cached", async () => {
|
||||||
|
self.LibResilientConfig = null
|
||||||
|
|
||||||
|
var configData = {loggedComponents: ['service-worker', 'cache'], plugins: [{name: "cache"}], defaultPluginTimeout: 5000}
|
||||||
|
global.fetch.mockImplementation((url, init) => {
|
||||||
|
return Promise.resolve(
|
||||||
|
new Response(
|
||||||
|
new Blob(
|
||||||
|
[JSON.stringify(configData)],
|
||||||
|
{type: "application/json"}
|
||||||
|
),
|
||||||
|
{
|
||||||
|
status: 200,
|
||||||
|
statusText: "OK",
|
||||||
|
headers: {
|
||||||
|
'ETag': 'TestingETagHeader'
|
||||||
|
},
|
||||||
|
url: url
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
require("../service-worker.js");
|
||||||
|
} catch(e) {}
|
||||||
|
await self.trigger('install')
|
||||||
|
// this is silly but works, and is necessary because
|
||||||
|
// event.waitUntil() in the install event handler is not handled correctly in NodeJS
|
||||||
|
await new Promise(resolve => resolve(true))
|
||||||
|
await self.trigger('activate')
|
||||||
|
expect(typeof self.LibResilientConfig).toEqual('object')
|
||||||
|
expect(self.LibResilientConfig.defaultPluginTimeout).toBe(5000)
|
||||||
|
expect(self.LibResilientConfig.plugins).toStrictEqual([{name: "cache"}])
|
||||||
|
expect(self.LibResilientConfig.loggedComponents).toStrictEqual(['service-worker', 'cache'])
|
||||||
|
// this is silly but works, and is necessary because... who knows, honestly?
|
||||||
|
await new Promise(resolve => resolve(true))
|
||||||
|
expect (await caches.open('v1').then((cache)=>{
|
||||||
|
return cache.match(self.location.origin + '/config.json')
|
||||||
|
}).then((response)=>{
|
||||||
|
return response.json()
|
||||||
|
}).then((json)=>{
|
||||||
|
return json
|
||||||
|
})).toStrictEqual({loggedComponents: ['service-worker', 'cache'], plugins: [{name: "cache"}], defaultPluginTimeout: 5000})
|
||||||
|
})
|
||||||
|
|
||||||
test("fetching content should work", async () => {
|
test("fetching content should work", async () => {
|
||||||
self.LibResilientConfig = {
|
self.LibResilientConfig = {
|
||||||
plugins: [{
|
plugins: [{
|
||||||
|
|
Ładowanie…
Reference in New Issue