diff --git a/integration/config_test.js b/integration/config_test.js index e6b8826210e006e5b65accb9c25035db9e7efd40..5d807de87394dcdd6db6f0696b6aebc8e1ca27d6 100644 --- a/integration/config_test.js +++ b/integration/config_test.js @@ -18,7 +18,7 @@ describe('Configuration', function () { 'index.html': {} }), '/index.html': () => new Response('<html><head></head><body>it\'s me</body></html>', { headers: { 'content-type': 'text/html' } }), - '/meta.json': td.when(td.func()(td.matchers.anything())).thenReturn( + '/meta.json': td.when(td.func()(td.matchers.anything(), td.matchers.anything())).thenReturn( new Response(JSON.stringify({ commitSha: '1' }), { headers: { 'Content-Type': 'application/json' } }), new Response(JSON.stringify({ commitSha: '2' }), { headers: { 'Content-Type': 'application/json' } }) ) diff --git a/integration/update-version_test.js b/integration/update-version_test.js index 15d3fc77204a50ffc48b622cfa3a22d4eae2cd14..0d40a75ca1878959d6de9864ddd59bf48cb3aa12 100644 --- a/integration/update-version_test.js +++ b/integration/update-version_test.js @@ -17,7 +17,7 @@ describe('Updates the version', function () { 'index.html': {} }), '/index.html': () => new Response('<html><head></head><body>it\'s me</body></html>', { headers: { 'content-type': 'text/html' } }), - '/meta.json': td.when(td.func()(td.matchers.anything())).thenReturn( + '/meta.json': td.when(td.func()(td.matchers.anything(), td.matchers.anything())).thenReturn( new Response(JSON.stringify({ commitSha: '1' }), { headers: { 'Content-Type': 'application/json' } }), new Response(JSON.stringify({ commitSha: '2' }), { headers: { 'Content-Type': 'application/json' } }), new Response(JSON.stringify({ commitSha: '2' }), { headers: { 'Content-Type': 'application/json' } }) diff --git a/spec/file_caching_test.js b/spec/file_caching_test.js index 3803ddb56771c5d13e8374ed7f7e79fd5ec263a9..cd6f198269de9984bfa358b24e608175a0291cc7 100644 --- a/spec/file_caching_test.js +++ b/spec/file_caching_test.js @@ -237,7 +237,7 @@ describe('File caching service', function () { '/manifest.json': generateSimpleViteManifest({ 'example.js': { } }), - '/example.js': td.when(td.func()(td.matchers.anything())).thenReturn( + '/example.js': td.when(td.func()(td.matchers.anything(), td.matchers.anything())).thenReturn( new Response('first', { headers: { 'content-type': 'text/plain' } }), new Response('second', { headers: { 'content-type': 'text/plain' } }) ) @@ -275,7 +275,7 @@ describe('File caching service', function () { '/manifest.json': generateSimpleViteManifest({ 'example.js': { } }), - '/example.js': td.when(td.func()(td.matchers.anything())).thenReturn( + '/example.js': td.when(td.func()(td.matchers.anything(), td.matchers.anything())).thenReturn( new Response('UI-container not available', { headers: { 'content-type': 'text/plain' }, status: 503 }), new Response('Now available', { headers: { 'content-type': 'text/plain' } }) ) @@ -298,7 +298,7 @@ describe('File caching service', function () { '/manifest.json': generateSimpleViteManifest({ 'example.js': { } }), - '/example.js': td.when(td.func()(td.matchers.anything())).thenReturn( + '/example.js': td.when(td.func()(td.matchers.anything(), td.matchers.anything())).thenReturn( new Response('Not found', { headers: { 'content-type': 'text/plain' }, status: 404 }), new Response('Now found', { headers: { 'content-type': 'text/plain' } }) ) diff --git a/spec/util.js b/spec/util.js index 23c361cf9272fe67621f6167b1b7d47769b857e9..a052a3c6d28365992b5239abeb2f64e12ce8c156 100644 --- a/spec/util.js +++ b/spec/util.js @@ -25,7 +25,7 @@ export function mockConfig (obj = {}) { } export function mockFetch (servers = {}) { - td.replace(global, 'fetch', async function ({ origin, pathname }) { + td.replace(global, 'fetch', async function ({ origin, pathname }, ...args) { const response = servers[origin]?.[pathname] if (response === undefined) return new Response('', { status: 404 }) if (response instanceof Function) return response.apply(this, arguments) diff --git a/src/files.js b/src/files.js index 757ff49260c8ee5ed4a041c005ffd5403704ccb1..c9f27e06cdff8438b51a3acdac5dedb38b719f00 100644 --- a/src/files.js +++ b/src/files.js @@ -34,7 +34,7 @@ async function createFileBuffer (response, dependencies) { export async function fetchFileWithHeadersFromBaseUrl (path, baseUrl, version) { const [response, dependencies] = await Promise.all([ - fetch(new URL(path, baseUrl)), + fetch(new URL(path, baseUrl), { cache: 'no-store' }), isJSFile(path) && getCSSDependenciesFor({ file: path.substr(1), version }) ]) diff --git a/src/manifests.js b/src/manifests.js index 14f71a0d81d0022512e6a3faccf8eafde7db90f2..209a7269f19052f96a96ff4da5ff390f2cc80011 100644 --- a/src/manifests.js +++ b/src/manifests.js @@ -11,7 +11,7 @@ export async function fetchViteManifests () { // from the corresponding registered services const viteManifests = await Promise.all(configMap.urls.map(async baseUrl => { // fetch the manifests - const result = await fetch(new URL('manifest.json', baseUrl)) + const result = await fetch(new URL('manifest.json', baseUrl), { cache: 'no-store' }) if (!result.ok) throw new Error(`Failed to load manifest for url ${result.url} (Status: ${result.status}: ${result.statusText})`) try { const manifest = await result.json() diff --git a/src/meta.js b/src/meta.js index 4f6209a07479e6fabfe4608cabe56260aeb7489e..c6d5761795570d00fcece6ff9c6fa2a5a16d7cee 100644 --- a/src/meta.js +++ b/src/meta.js @@ -6,7 +6,7 @@ export async function fetchMergedMetadata () { const metadata = await Promise.all(configMap.urls.map(async url => { const { origin } = new URL(url) try { - const response = await fetch(new URL('meta.json', origin)) + const response = await fetch(new URL('meta.json', origin), { cache: 'no-store' }) if (!response.ok) return return response.json() } catch (e) { diff --git a/src/version.js b/src/version.js index 615a095751b4da728810b03bfb12e4ec1a131a4b..e87b7da3632390c0292009f778a224addb5199dc 100644 --- a/src/version.js +++ b/src/version.js @@ -27,7 +27,7 @@ const versionUpdateGauge = new Gauge({ export const fetchLatestVersion = async () => { const infos = await Promise.all(configMap.urls.map(async baseUrl => { try { - const response = await fetch(new URL('meta.json', baseUrl)) + const response = await fetch(new URL('meta.json', baseUrl), { cache: 'no-store' }) if (!response.ok) throw new Error() const meta = await response.json() const version = meta.commitSha || meta.buildDate || meta.version @@ -36,7 +36,7 @@ export const fetchLatestVersion = async () => { } catch (err) { logger.warn(`[Version] UI container at ${baseUrl} does not have meta.json. Fall back to version hash based on manifest.`) } - const response = await fetch(new URL('manifest.json', baseUrl)) + const response = await fetch(new URL('manifest.json', baseUrl), { cache: 'no-store' }) if (!response.ok) throw new Error(`Cannot fetch manifest.json from ${baseUrl}`) const manifest = await response.json() return hash(manifest)