Skip to content

Commit 7cca69c

Browse files
committed
test: more cleanup
1 parent 6965a42 commit 7cca69c

1 file changed

Lines changed: 14 additions & 33 deletions

File tree

packages/plugin-vite/tests/build_test.ts

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ Deno.test({
476476
});
477477

478478
Deno.test({
479-
name: "vite build - basePath CSS links are correctly prefixed",
479+
name: "vite build - basePath asset links are correctly prefixed",
480480
fn: async () => {
481481
await using res = await buildVite(DEMO_DIR, { base: "/ui/" });
482482

@@ -488,51 +488,32 @@ Deno.test({
488488
waitUntil: "networkidle2",
489489
});
490490

491+
// Test CSS links are prefixed correctly
491492
const stylesheetHrefs = await page.evaluate(() => {
492493
const links = Array.from(
493494
document.querySelectorAll('link[rel="stylesheet"]'),
494495
);
495496
return links.map((link) => (link as HTMLLinkElement).href);
496497
});
497498

498-
// All CSS links should include the basePath /ui/
499499
stylesheetHrefs.forEach((href) => {
500500
expect(href).toMatch(/\/ui\/assets\/.*\.css/);
501501
});
502-
});
503-
},
504-
);
505-
},
506-
sanitizeOps: false,
507-
sanitizeResources: false,
508-
});
509-
510-
Deno.test({
511-
name: "vite build - basePath image links are correctly prefixed",
512-
fn: async () => {
513-
await using res = await buildVite(DEMO_DIR, { base: "/ui/" });
514502

515-
// Read the generated server.js to check that image assets have basePath applied
516-
const serverJs = await Deno.readTextFile(
517-
path.join(res.tmp, "_fresh", "server.js"),
518-
);
519-
520-
// The server.js should contain image assets with the basePath /ui/
521-
// Look for the deno-logo.png asset registration
522-
expect(serverJs).toContain('"/ui/assets/deno-logo-');
523-
expect(serverJs).toContain('.png"');
524-
525-
// Verify the basePath is properly applied to all assets, not just CSS
526-
const assetRegistrations = serverJs.match(
527-
/registerStaticFile\({[^}]+}\);/g,
528-
);
529-
expect(assetRegistrations).toBeTruthy();
503+
// Test image links are prefixed correctly
504+
const imageSrcs = await page.evaluate(() => {
505+
const images = Array.from(document.querySelectorAll("img"));
506+
return images.map((img) => img.src).filter((src) =>
507+
src.includes("/assets/")
508+
);
509+
});
530510

531-
// Check that image assets (png files) have the correct basePath
532-
const imageRegistrations = assetRegistrations?.filter((reg) =>
533-
reg.includes(".png") && reg.includes('"/ui/assets/')
511+
imageSrcs.forEach((src) => {
512+
expect(src).toMatch(/\/ui\/assets\//);
513+
});
514+
});
515+
},
534516
);
535-
expect(imageRegistrations && imageRegistrations.length > 0).toBe(true);
536517
},
537518
sanitizeOps: false,
538519
sanitizeResources: false,

0 commit comments

Comments
 (0)