Synchronize verified assets incrementally and guard update activation
This commit is contained in:
@@ -32,11 +32,11 @@ async function freePort() {
|
||||
});
|
||||
}
|
||||
|
||||
async function startServer(hashing = true) {
|
||||
async function startServer(hashing = true, sync = true) {
|
||||
const port = await freePort();
|
||||
const child = Bun.spawn([process.execPath, serverFile], {
|
||||
cwd: root,
|
||||
env: { ...process.env, PORT: String(port), ASSET_HASHING: hashing ? '1' : '0', BUILD_TAG: '', DB_PATH: join(dataDir, `db-${port}.sqlite`), MEDIA_DIR: join(dataDir, 'media'), UPLOAD_DIR: join(dataDir, 'uploads') },
|
||||
env: { ...process.env, PORT: String(port), ASSET_HASHING: hashing ? '1' : '0', ASSET_SYNC: sync ? '1' : '0', BUILD_TAG: '', DB_PATH: join(dataDir, `db-${port}.sqlite`), MEDIA_DIR: join(dataDir, 'media'), UPLOAD_DIR: join(dataDir, 'uploads') },
|
||||
stdout: 'pipe', stderr: 'pipe',
|
||||
});
|
||||
const stdout = new Response(child.stdout).text();
|
||||
@@ -168,6 +168,19 @@ describe('static delivery characterization', () => {
|
||||
} finally { await stopServer(server); server = await startServer(); }
|
||||
});
|
||||
|
||||
test('manifest compression preserves build ETag and sync mode is injected', async () => {
|
||||
const version=await (await fetch(`${server.base}/api/version`)).json();
|
||||
const response=await fetch(`${server.base}/api/manifest`,{headers:{'Accept-Encoding':'gzip'}});
|
||||
expect(response.headers.get('etag')).toBe(`"${version.buildTag}"`);
|
||||
expect(response.headers.get('content-encoding')).toBe('gzip');
|
||||
expect((await response.json()).buildTag).toBe(version.buildTag);
|
||||
writeFileSync(join(publicDir,'sw.js'), "const BUILD_TAG = typeof __BUILD_TAG__ !== 'undefined' ? __BUILD_TAG__ : 'v-test'; const SYNC = typeof __ASSET_SYNC__ !== 'undefined' ? __ASSET_SYNC__ : true;");
|
||||
await stopServer(server);server=await startServer(true,false);
|
||||
expect(await (await fetch(`${server.base}/sw.js`)).text()).toContain('const SYNC = false');
|
||||
await stopServer(server);server=await startServer(true,true);
|
||||
expect(await (await fetch(`${server.base}/sw.js`)).text()).toContain('const SYNC = true');
|
||||
});
|
||||
|
||||
test('service worker injection tracks fallback literal and reports missing placeholder', async () => {
|
||||
let sw = await (await fetch(`${server.base}/sw.js`)).text();
|
||||
const { buildTag } = await (await fetch(`${server.base}/api/version`)).json();
|
||||
|
||||
Reference in New Issue
Block a user