From a67f157cffec5900e04bf1246ac98bfe5f95ce85 Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Fri, 19 May 2017 17:57:47 +0700 Subject: [PATCH] Test stale cache entries that can't be revalidate are deleted from cache --- test/cache.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/cache.js b/test/cache.js index 441ee2e..ea5490f 100644 --- a/test/cache.js +++ b/test/cache.js @@ -48,6 +48,14 @@ test.before('setup', async () => { res.end(responseBody); }); + let cacheThenNoStoreIndex = 0; + s.on('/cache-then-no-store-on-revalidate', (req, res) => { + const cc = cacheThenNoStoreIndex === 0 ? 'public, max-age=0' : 'public, no-cache, no-store'; + cacheThenNoStoreIndex++; + res.setHeader('Cache-Control', cc); + res.end('cache-then-no-store-on-revalidate'); + }); + await s.listen(s.port); }); @@ -140,6 +148,21 @@ test('Stale cache entries with ETag headers are revalidated', async t => { t.is(firstResponse.body, secondResponse.body); }); +test('Stale cache entries that can\'t be revalidate are deleted from cache', async t => { + const endpoint = '/cache-then-no-store-on-revalidate'; + const cache = new Map(); + + const firstResponse = await got(s.url + endpoint, {cache}); + t.is(cache.size, 1); + const secondResponse = await got(s.url + endpoint, {cache, log: true}); + + t.is(cache.size, 0); + t.is(firstResponse.statusCode, 200); + t.is(secondResponse.statusCode, 200); + t.is(firstResponse.body, 'cache-then-no-store-on-revalidate'); + t.is(firstResponse.body, secondResponse.body); +}); + test.after('cleanup', async () => { await s.close(); });