test(e2e): assert static assets resolve under a custom base path (#4880)

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Amir Raminfar
2026-07-30 07:20:19 -07:00
committed by GitHub
parent 5e0a4c43e6
commit 18acf6722b
+36 -1
View File
@@ -1,7 +1,10 @@
import { test, expect } from "@playwright/test";
const origin = "http://custom_base:8080";
const base = "/foobarbase";
test.beforeEach(async ({ page }) => {
await page.goto("http://custom_base:8080/foobarbase");
await page.goto(origin + base);
});
test("has right title", async ({ page }) => {
@@ -11,3 +14,35 @@ test("has right title", async ({ page }) => {
test("url should have custom base", async ({ page }) => {
await expect(page).toHaveURL(/foobarbase/);
});
test("static assets resolve under the custom base", async ({ page }) => {
const requested: string[] = [];
const broken: string[] = [];
const isAsset = (url: string) => new URL(url).pathname.includes("/assets/");
page.on("request", (request) => {
if (isAsset(request.url())) requested.push(new URL(request.url()).pathname);
});
page.on("response", (response) => {
if (isAsset(response.url()) && response.status() >= 400) {
broken.push(`${response.status()} ${response.url()}`);
}
});
await page.reload();
await expect(page).toHaveTitle(/.* - Dozzle/);
// fonts are only fetched when a glyph needs them, so force the @font-face src to resolve.
// swallow the rejection on a bad url so the assertions below report which path was wrong
await page.evaluate(() =>
document.fonts.load('400 1rem "JetBrains Mono"').then(
() => {},
() => {},
),
);
// the css lives at <base>/assets/, so a relative url() in it must resolve back under <base>
expect(requested.some((path) => path.endsWith(".woff2"))).toBe(true);
expect(requested.filter((path) => !path.startsWith(`${base}/assets/`))).toEqual([]);
expect(broken).toEqual([]);
});