mirror of
https://github.com/amir20/dozzle.git
synced 2026-08-07 09:04:44 +00:00
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:
+36
-1
@@ -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([]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user