Files
AndreaSlopFotografie/web/e2e/support/server.ts
T
SluijsensandClaude Sonnet 5.5 bf21b6f690 Builds the markers, data block and stand-in host for the CMS host injection
The pages carry the CMS markers (data block, list regions, JSON-LD price,
inline price); PackagesProvider reads the host's data block after hydration
and asks the API only when there is none; the site address comes from the
block. A stand-in for the host (config/hostInjector.ts, --cms-data in the
preview server) and browser tests check the behaviour with different data.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 16:21:08 +01:00

35 lines
1.5 KiB
TypeScript

import type { AddressInfo } from 'node:net';
import { resolve } from 'node:path';
import type { InjectOptions } from '../../config/hostInjector.ts';
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.
// inject laat de server doen alsof de CMS-host de markers vult (hostInjector)
export async function startServer(
options: { auditRoute?: boolean; inject?: () => InjectOptions | null } = {},
) {
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();
}),
};
}