Skip to content
Snippets Groups Projects
Commit 15b00515 authored by richard.petersen's avatar richard.petersen :sailboat:
Browse files

Fix: /ready might trigger warmup multiple times

parent 32b50eb5
No related branches found
No related tags found
No related merge requests found
import { generateSimpleViteManifest, mockApp, mockConfig, mockFetch } from './util.js'
import { expect } from 'chai'
import * as td from 'testdouble'
import { Response } from 'node-fetch'
describe('Service startup', function () {
before(async function () {
mockConfig({ urls: ['http://ui-server/'] })
})
after(function () {
td.reset()
})
it('only fetches all files once', async function () {
const counters = {
'/example.js': 0,
'/test.txt': 0,
'/index.html.js': 0,
'/index.html': 0
}
mockFetch({
'http://ui-server': {
'/manifest.json': generateSimpleViteManifest({
'example.js': { imports: ['test.txt'] },
'test.txt': { },
'index.html': {
file: 'index.html.js',
isEntry: true,
imports: ['example.js']
}
}),
'/example.js': () => {
counters['/example.js']++
return new Response('this is example', { headers: { 'content-type': 'application/javascript' } })
},
'/test.txt': () => {
counters['/test.txt']++
return new Response('this is test', { headers: { 'content-type': 'text/plain' } })
},
'/index.html.js': () => {
counters['/index.html.js']++
return new Response('this is index.html.js', { headers: { 'content-type': 'application/javascript' } })
},
'/index.html': () => {
counters['/index.html']++
return new Response('<html><head></head><body>it\'s me</body></html>', { headers: { 'content-type': 'text/html' } })
}
}
})
await mockApp()
Object.entries(counters).forEach(([key, value]) => {
expect(value, `${key}`).to.equal(1)
})
})
})
......@@ -38,9 +38,14 @@ class FileCache {
this._hash = ''
this._dependencies = {}
this._oxManifests = {}
this._isCaching = false
}
async warmUp (manifests, deps) {
if (this._hash === manifests.__hash__) return logger.debug(`Tried to warm up the filecache with the same version: ${manifests.__hash__}`)
if (this._isCaching) return logger.debug('Cache.warmup is already running')
this._isCaching = true
logger.debug('beginning to warm up cache')
const cache = Object.fromEntries(await (async function () {
const files = Object.keys(deps)
......@@ -79,6 +84,7 @@ class FileCache {
this._hash = manifests.__hash__
this._dependencies = deps
this._oxManifests = viteToOxManifest(manifests)
this._isCaching = false
logger.debug('cache warmed up')
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment