diff --git a/spec/file_caching_test.js b/spec/file_caching_test.js index 71c79814f8c04d47ef2c59bdc3777f9cfc7887d8..ccad2ea2497841b369e7722cb77cfe851207cfd9 100644 --- a/spec/file_caching_test.js +++ b/spec/file_caching_test.js @@ -12,6 +12,7 @@ describe('File caching service', function () { let app before(async function () { + let count = 0 mockConfig({ urls: ['http://ui-server/'] }) mockFetch({ 'http://ui-server': { @@ -33,6 +34,13 @@ describe('File caching service', function () { '/index.html': () => new Response('<html><head></head><body>it\'s me</body></html>', { headers: { 'content-type': 'text/html' } }), '/main.css': () => new Response('.foo { color: #000; }', { headers: { 'content-type': 'text/css' } }), '/favicon.ico': 'not really a favicon, though', + '/test.svg': () => { + if (count > 0) { + return new Response(null, { status: 404 }) + } + count++ + return new Response('<svg></svg>', { headers: { 'content-type': 'image/svg' } }) + }, '/image.png': () => { return new Response(image, { headers: { @@ -89,6 +97,15 @@ describe('File caching service', function () { expect(response.text).to.equal('not really a favicon, though') }) + it('caches files not referenced in manifest.json fetched from upstream servers', async function () { + let response = await request(app).get('/test.svg') + expect(response.statusCode).to.equal(200) + expect(String(response.body)).to.equal('<svg></svg>') + response = await request(app).get('/test.svg') + expect(response.statusCode).to.equal(200) + expect(String(response.body)).to.equal('<svg></svg>') + }) + it('returns 404 if file can not be resolved', async function () { const response = await request(app).get('/unknown-file.txt') expect(response.statusCode).to.equal(404) diff --git a/src/files.js b/src/files.js index 81413a959aac47d18bf146a8818c56c094b24966..815f7d627f5f262aeae10ad02ab27fb79bd6dd52 100644 --- a/src/files.js +++ b/src/files.js @@ -94,7 +94,7 @@ class FileCache { const [[key, value]] = (await Promise.allSettled(config.urls.map(baseUrl => fetchData(path, baseUrl)))) .filter(r => r.status === 'fulfilled').map(r => r.value) - this._cache[key] = value + this._cache[key.slice(1)] = value return value }