fix: register files generated by Vite plugins in static file cache (#3534)
Fixes #3487 --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Bartek Iwańczuk
Claude Opus 4.6
parent
400e217c5e
commit
8b0d42b82a
@@ -664,3 +664,65 @@ Deno.test({
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "vite build - vite-plugin-pwa generates service worker",
|
||||
fn: async () => {
|
||||
const fixture = path.join(FIXTURE_DIR, "vite_plugin_pwa");
|
||||
await using res = await buildVite(fixture);
|
||||
|
||||
// Verify that vite-plugin-pwa generated the expected files in _fresh/client
|
||||
const swPath = path.join(res.tmp, "_fresh", "client", "sw.js");
|
||||
const manifestPath = path.join(
|
||||
res.tmp,
|
||||
"_fresh",
|
||||
"client",
|
||||
"manifest.webmanifest",
|
||||
);
|
||||
|
||||
// Check that files were generated
|
||||
const swStat = await Deno.stat(swPath);
|
||||
expect(swStat.isFile).toEqual(true);
|
||||
|
||||
const manifestStat = await Deno.stat(manifestPath);
|
||||
expect(manifestStat.isFile).toEqual(true);
|
||||
},
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "vite build - vite-plugin-pwa files are accessible via HTTP",
|
||||
fn: async () => {
|
||||
const fixture = path.join(FIXTURE_DIR, "vite_plugin_pwa");
|
||||
await using res = await buildVite(fixture);
|
||||
|
||||
await launchProd(
|
||||
{ cwd: res.tmp },
|
||||
async (address) => {
|
||||
// Test that service worker is accessible
|
||||
const swRes = await fetch(`${address}/sw.js`);
|
||||
expect(swRes.status).toEqual(200);
|
||||
expect(swRes.headers.get("content-type")).toMatch(/javascript/);
|
||||
|
||||
const swContent = await swRes.text();
|
||||
expect(swContent.length).toBeGreaterThan(0);
|
||||
|
||||
// Test that manifest is accessible
|
||||
const manifestRes = await fetch(`${address}/manifest.webmanifest`);
|
||||
expect(manifestRes.status).toEqual(200);
|
||||
expect(manifestRes.headers.get("content-type")).toMatch(/json/);
|
||||
|
||||
const manifestContent = await manifestRes.json();
|
||||
expect(manifestContent.name).toEqual("Fresh PWA Test");
|
||||
|
||||
// Test that registerSW.js is accessible
|
||||
const registerRes = await fetch(`${address}/registerSW.js`);
|
||||
expect(registerRes.status).toEqual(200);
|
||||
expect(registerRes.headers.get("content-type")).toMatch(/javascript/);
|
||||
},
|
||||
);
|
||||
},
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user