kopia lustrzana https://gitlab.com/rysiekpl/libresilient
service-worker: test for external urls added (ref. #8)
rodzic
4ca07d1477
commit
7bd024f2c7
|
@ -109,6 +109,44 @@ describe("service-worker", () => {
|
|||
expect(response.headers.get('X-LibResilient-ETag')).toEqual('TestingETagHeader')
|
||||
});
|
||||
|
||||
test("making an external request should work and not go through the plugins", async () => {
|
||||
global.fetch.mockImplementation((request, init) => {
|
||||
return Promise.resolve(
|
||||
new Response(
|
||||
new Blob(
|
||||
[JSON.stringify({ test: "success" })],
|
||||
{type: "application/json"}
|
||||
),
|
||||
{
|
||||
status: 200,
|
||||
statusText: "OK",
|
||||
headers: {
|
||||
'ETag': 'TestingETagHeader'
|
||||
},
|
||||
method: 'GET',
|
||||
url: request.url
|
||||
})
|
||||
);
|
||||
});
|
||||
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");
|
||||
var response = await self.trigger('fetch', new Request('https://example.com/test.json'))
|
||||
expect(await response.json()).toEqual({ test: "success" })
|
||||
})
|
||||
|
||||
test("making a POST request should work and not go through the plugins", async () => {
|
||||
global.fetch.mockImplementation((request, init) => {
|
||||
return Promise.resolve(
|
||||
|
|
Ładowanie…
Reference in New Issue