Lets the deployment check cope with pages the CMS host has filled

The check after a deploy compared the server's answer with dist byte for byte,
which fails once the host writes current data into the markers. Both sides are
now normalised first (regions, data block, offers, inline prices, site
address); everything else still has to match. The stand-in host no longer
injects the 404 page, like the real one.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 17:02:17 +01:00
co-authored by Claude Sonnet 5.5
parent b2cb6351e1
commit d9ff875ade
5 changed files with 207 additions and 2 deletions
+106
View File
@@ -0,0 +1,106 @@
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { describe, expect, it } from 'vitest';
import { injectCms, type LiveData } from './hostInjector.ts';
import { normalizeInjected } from './normalizeInjected.ts';
const AUTHORED = 'https://andreaslop.nl';
const baked = (name: string) => {
try {
return readFileSync(
join(process.cwd(), 'dist', 'client', name),
'utf8',
);
} catch {
return null;
}
};
const live: LiveData = {
offerings: [
{
slug: 'newborn',
title: 'Newborn',
price: '€ 999',
features: ['x'],
displayOrder: 0,
},
],
banners: { top: { text: 'Boven' }, bottom: null },
};
describe('normalizeInjected', () => {
it('makes a page equal to the same page after the host filled the markers', () => {
const pages = ['index.html', 'soorten-fotoshoots/newborn.html'];
for (const page of pages) {
const html = baked(page);
// The tests of the unit run need no build; skip a page that is not built
if (html === null) continue;
const injected = injectCms(html, {
data: live,
authoredBaseUrl: AUTHORED,
publicBaseUrl: 'https://test.example.nl',
});
expect(injected).not.toBe(html);
expect(
normalizeInjected(injected, [
AUTHORED,
'https://test.example.nl',
]),
).toBe(
normalizeInjected(html, [AUTHORED, 'https://test.example.nl']),
);
}
});
const page = (inner: string) => `<body>${inner}</body>`;
it('empties the regions but keeps the markers', () => {
expect(
normalizeInjected(
page('<!--CMS:OFFERINGS-HTML-->a<!--/CMS:OFFERINGS-HTML-->'),
),
).toBe(page('<!--CMS:OFFERINGS-HTML--><!--/CMS:OFFERINGS-HTML-->'));
});
it('removes the data block with or without its marker', () => {
const block =
'<script type="application/json" id="cms-data">{}</script>';
expect(normalizeInjected(page('<!--CMS:DATA-->' + block))).toBe(
page(''),
);
expect(normalizeInjected(page(block))).toBe(page(''));
expect(normalizeInjected(page('<!--CMS:DATA-->'))).toBe(page(''));
});
it('drops offers from structured data and the marker before it', () => {
const withOffers =
'<!--CMS:OFFER-JSON-LD slug="x"--><script type="application/ld+json">{"a":1,"offers":{"price":1}}</script>';
const without =
'<script type="application/ld+json">{ "a": 1 }</script>';
expect(normalizeInjected(page(withOffers))).toBe(
normalizeInjected(page(without)),
);
});
it('leaves structured data that is not JSON, so it still differs', () => {
const broken = '<script type="application/ld+json">{kapot</script>';
expect(normalizeInjected(page(broken))).toBe(page(broken));
});
it('empties inline prices and replaces the site addresses', () => {
expect(
normalizeInjected(
page('<span data-cms-price="x" a>€ 5</span> https://a.nl/x'),
['https://a.nl'],
),
).toBe(page('<span data-cms-price="x" a></span> @SITE@/x'));
});
it('still sees a real difference', () => {
expect(normalizeInjected(page('<p>een</p>'))).not.toBe(
normalizeInjected(page('<p>twee</p>')),
);
});
});