Adds the step that moves inline scripts to files

TanStack Start writes inline scripts into each page, which the strict CSP
blocks. This step moves them to hashed files and checks the output: every page
is present, no executable inline script remains and the e-mail address appears
nowhere. It is not part of the build yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-31 18:12:42 +01:00
co-authored by Claude Opus 5.5
parent c1e90f0768
commit 1574726c1d
8 changed files with 2409 additions and 4 deletions
+84
View File
@@ -0,0 +1,84 @@
import fc from 'fast-check';
import { describe, expect, it } from 'vitest';
import sitePages from '../src/sitePages';
import { routePath } from '../src/test/arbitraries';
import {
NOT_FOUND_FILE,
NOT_FOUND_PATH,
pageFile,
pagePath,
} from './pageFiles';
describe('pageFile', () => {
it.each([
['/', 'index.html'],
['/over-mij', 'over-mij.html'],
['/soorten-fotoshoots', 'soorten-fotoshoots.html'],
['/soorten-fotoshoots/newborn', 'soorten-fotoshoots/newborn.html'],
[NOT_FOUND_PATH, NOT_FOUND_FILE],
])('%s staat in %s', (path, file) => {
expect(pageFile(path)).toBe(file);
});
it('begint nooit met een slash en eindigt op .html (invariant)', () => {
fc.assert(
fc.property(routePath, (path) => {
const file = pageFile(path);
expect(file.startsWith('/')).toBe(false);
expect(file.endsWith('.html')).toBe(true);
}),
);
});
});
describe('pagePath', () => {
it.each([
['index.html', '/'],
['over-mij.html', '/over-mij'],
['soorten-fotoshoots/newborn.html', '/soorten-fotoshoots/newborn'],
])('%s hoort bij %s', (file, path) => {
expect(pagePath(file)).toBe(path);
});
it.each([
['404.html', 'de 404-pagina is geen pagina uit het register'],
['assets/index-abc.js', 'geen html'],
['sitemap.xml', 'geen html'],
['over-mij.htm', 'andere extensie'],
['over-mij', 'zonder extensie'],
['.html', 'zonder naam'],
['/over-mij.html', 'met voorste slash'],
])('%s is geen paginabestand (%s)', (file) => {
expect(pagePath(file)).toBeUndefined();
});
it('geeft index.html voor /index, dus /index is geen eigen pagina', () => {
expect(pageFile('/index')).toBe('index.html');
expect(pagePath(pageFile('/index'))).toBe('/');
});
});
describe('pageFile en pagePath samen', () => {
it('geven elk pad uit het register terug (round-trip)', () => {
for (const path of Object.keys(sitePages)) {
expect(pagePath(pageFile(path))).toBe(path);
}
});
it('geven elk routepad terug (round-trip)', () => {
fc.assert(
fc.property(
// /index valt samen met het bestand van / (zie hierboven)
routePath.filter((path) => path !== '/index'),
(path) => {
expect(pagePath(pageFile(path))).toBe(path);
},
),
);
});
it('geven aan de 404-pagina geen pad terug', () => {
expect(pageFile(NOT_FOUND_PATH)).toBe(NOT_FOUND_FILE);
expect(pagePath(NOT_FOUND_FILE)).toBeUndefined();
});
});