Files
AndreaSlopFotografie/web/e2e/support/server.ts
T
SluijsensandClaude Sonnet 5.5 7737104a77 Lets the CI preview server stand in for the contact API
With contactForm.enabled=true the e2e and Lighthouse runs asked a token route
that CI does not have (404, console error, run 666). The preview server gets an
opt-in --contact-stub (token 200 without captcha, submit 202); the e2e server
helper and the Lighthouse start command switch it on. Tests that need another
answer still replace it per page with page.route.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-11 19:39:03 +01:00

31 lines
1.3 KiB
TypeScript

import type { AddressInfo } from 'node:net';
import { resolve } from 'node:path';
import { startPreviewServer } from '../../config/previewServer.ts';
// De gebouwde site: `pnpm build` schrijft hem, de tests bouwen niets. Relatief
// aan de werkmap (web/), zoals `pnpm preview`; import.meta.url is in een
// jsdom-testbestand geen bestands-URL.
export const clientDir = resolve('dist/client');
// Dezelfde server als `pnpm preview`, met de productie-CSP en echte 404's,
// op een poort die het systeem kiest zodat tests elkaar niet in de weg zitten.
// auditRoute zet de opt-in route /__audit/404 aan, zoals Lighthouse hem start.
// De contact-API wordt standaard nagebootst (CI heeft geen CMS-host); een
// test die iets anders nodig heeft vervangt het met page.route.
export async function startServer(options: { auditRoute?: boolean } = {}) {
const server = await startPreviewServer(clientDir, 0, {
contactStub: true,
...options,
});
const { port } = server.address() as AddressInfo;
return {
origin: `http://127.0.0.1:${port}`,
close: () =>
new Promise<void>((resolve, reject) => {
server.close((error) => (error ? reject(error) : resolve()));
// Open keep-alive-verbindingen van Chrome houden close() op
server.closeAllConnections();
}),
};
}