Skip to content

Commit

Permalink
Extending test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Gaunt committed Jan 4, 2018
1 parent 335e588 commit a73c948
Showing 1 changed file with 74 additions and 1 deletion.
75 changes: 74 additions & 1 deletion test/workbox-precaching/node/controllers/test-default.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ describe(`[workbox-precaching] default export`, function() {
expect(response).to.equal(cachedResponse);
});

it.only(`should use the cleanUrls of 'about.html'`, async function() {
it(`should use the cleanUrls of 'about.html'`, async function() {
let fetchCb;
sandbox.stub(self, 'addEventListener').callsFake((eventName, cb) => {
if (eventName === 'fetch') {
Expand Down Expand Up @@ -294,6 +294,79 @@ describe(`[workbox-precaching] default export`, function() {
expect(response).to.equal(cachedResponse);
});

it(`should *not* use the cleanUrls of 'about.html' if set to false`, async function() {
let fetchCb;
sandbox.stub(self, 'addEventListener').callsFake((eventName, cb) => {
if (eventName === 'fetch') {
fetchCb = cb;
}
});

const PRECACHED_FILE = 'about.html';

const cachedResponse = new Response('Injected Response');
const cache = await caches.open(core.cacheNames.precache);
cache.put(new URL(`/${PRECACHED_FILE}`, location).href, cachedResponse);

precaching.addRoute({
cleanUrls: false,
});
precaching.precache([`/${PRECACHED_FILE}`]);

const fetchEvent = new FetchEvent('fetch', {
request: new Request(`/about`),
});
let fetchPromise;
fetchEvent.respondWith = (promise) => {
fetchPromise = promise;
};
fetchCb(fetchEvent);

const response = await fetchPromise;
expect(response).to.not.exist;
});

it(`should use custom urlManipulation function`, async function() {
let fetchCb;
sandbox.stub(self, 'addEventListener').callsFake((eventName, cb) => {
if (eventName === 'fetch') {
fetchCb = cb;
}
});

const PRECACHED_FILE = '123.html';

const cachedResponse = new Response('Injected Response');
const cache = await caches.open(core.cacheNames.precache);
cache.put(new URL(`/${PRECACHED_FILE}`, location).href, cachedResponse);

precaching.addRoute({
urlManipulation: ({url}) => {
expect(url.pathname).to.equal('/');

const customUrl = new URL(url);
customUrl.pathname = '123.html';
return [
customUrl,
];
},
});
precaching.precache([`/${PRECACHED_FILE}`]);

const fetchEvent = new FetchEvent('fetch', {
request: new Request(`/`),
});
let fetchPromise;
fetchEvent.respondWith = (promise) => {
fetchPromise = promise;
};
fetchCb(fetchEvent);

const response = await fetchPromise;
expect(response).to.exist;
expect(response).to.equal(cachedResponse);
});

it(`should return null if there is no match`, async function() {
let fetchCb;
sandbox.stub(self, 'addEventListener').callsFake((eventName, cb) => {
Expand Down

0 comments on commit a73c948

Please sign in to comment.