Compares the preview server with real nginx in tests

The preview server must behave like the real server, or Lighthouse and the
browser tests prove the wrong thing. The tests also cover the new URLs in a real
browser: one redirect, one title, a clean hydration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-01 18:30:08 +01:00
co-authored by Claude Opus 5.5
parent e4e7f8c82c
commit 38708b8439
10 changed files with 539 additions and 88 deletions
+25 -45
View File
@@ -25,9 +25,9 @@ const notFoundPaths = [
'/soorten-fotoshoots/onbekend',
];
// Alleen een document dat de server bewust met 404 beantwoordt (BR-SRV-05)
const expectedStatus = (path: string) =>
path === '/404.html' || pages.includes(path) ? 200 : 404;
// Alleen een document dat de server bewust met 404 beantwoordt (BR-SRV-05);
// /404 en /404.html zijn echte 404's (BR-HST-05)
const expectedStatus = (path: string) => (pages.includes(path) ? 200 : 404);
describe.each(widths)('hydratatie op %i px', (width) => {
it.each([...pages, ...notFoundPaths])(
@@ -74,6 +74,7 @@ describe('de 404-pagina, gemaakt voor /404 en getoond op een andere URL', () =>
server.origin + '/404.html',
{
width,
expectNotFound: true,
prepare: async (page) => {
await page.route(
/\/assets\/_-[^/]+\.js$/,
@@ -282,47 +283,26 @@ describe('contactformulier op /contact (V8)', () => {
});
});
// BR-404-07: een URL die de server niet kent maar de router wel. Dit is een
// waarneming, geen controle die de suite laat falen. De
// preview-server draait op Windows en Linux anders (hoofdletters in
// bestandsnamen), dus de Linux-situatie wordt nagespeeld: 404.html met 404.
describe('URL die de server niet kent en de router wel (BR-404-07)', () => {
it.each(['/Over-Mij', '/over-mij/'])('observeert %s', async (path) => {
const real = await fetch(server.origin + path, { redirect: 'manual' });
const observe = async (
served: string,
prepare?: (page: Page) => Promise<void>,
) => {
const { page, ...opened } = await openPage(server.origin + path, {
prepare,
// BR-404-07, BR-HST-08: een URL die de router wel kent maar de server niet als
// pagina bedient kan geen verschil tussen HTML en eerste render meer geven,
// want de server verwijst hem eerst door naar het canonieke pad. Het volledige
// gedrag in Chrome staat in urls.e2e.ts.
describe('URL die alleen de router kent wordt doorverwezen (BR-HST-08)', () => {
it.each(['/Over-Mij', '/over-mij/'])(
'%s gaat met één 301 naar /over-mij',
async (path) => {
const real = await fetch(server.origin + path, {
redirect: 'manual',
});
await page.waitForTimeout(1500);
const state = await page.evaluate(() => ({
url: location.pathname,
h1: document.querySelector('h1')?.textContent,
titles: [...document.querySelectorAll('title')].map(
(t) => t.textContent,
),
}));
console.info(
`BR-404-07 ${path} (${served}): ${JSON.stringify({ ...state, status: opened.status, messages: opened.messages })}`,
);
};
console.info(
`BR-404-07 ${path}: preview-server geeft ${real.status} ${real.headers.get('content-type')}`,
);
await observe('preview-server van deze machine');
await observe(
'404.html met 404, zoals een hoofdlettergevoelige host',
async (page) => {
await page.route(server.origin + path, async (route) => {
const notFound = await route.fetch({
url: server.origin + '/404.html',
});
await route.fulfill({ response: notFound, status: 404 });
});
},
);
expect(real.status).toBeGreaterThan(0);
});
expect(real.status).toBe(301);
expect(real.headers.get('location')).toBe('/over-mij');
const { page, ...opened } = await openPage(server.origin + path);
await waitForHydration(page);
expect(new URL(page.url()).pathname).toBe('/over-mij');
expect(opened.status).toBe(200);
expect(opened.messages).toEqual([]);
expect(opened.violations).toEqual([]);
},
);
});