Only the generic structural loop test covered
taxonomy-chrnx_{project,show,release}.html; nothing asserted their
block content, so the journal-stream regression fixed last round
would have gone uncaught if it recurred. Add content tests for the
project and show templates mirroring the existing archive/search idiom.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
119 lines
4.8 KiB
JavaScript
119 lines
4.8 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { readFile } from 'node:fs/promises';
|
|
import test from 'node:test';
|
|
|
|
const templates = [ 'home', 'single', 'page', 'archive', 'search', '404', 'taxonomy-chrnx_project', 'taxonomy-chrnx_show', 'taxonomy-chrnx_release' ];
|
|
const readTemplate = (name) => readFile(new URL(`../../templates/${name}.html`, import.meta.url), 'utf8');
|
|
|
|
function assertBalancedBlockMarkup(markup, name) {
|
|
const stack = [];
|
|
for (const match of markup.matchAll(/<!--\s+(\/?)wp:([a-z0-9-]+(?:\/[a-z0-9-]+)?)(?:\s+\{.*?\})?\s*(\/?)-->/gs)) {
|
|
const [, closing, blockName, selfClosing] = match;
|
|
if (selfClosing) continue;
|
|
if (!closing) {
|
|
stack.push(blockName);
|
|
continue;
|
|
}
|
|
assert.equal(stack.pop(), blockName, `${name} must close ${blockName} in order`);
|
|
}
|
|
assert.deepEqual(stack, [], `${name} must close every WordPress block`);
|
|
}
|
|
|
|
for (const name of templates) {
|
|
test(`${name}.html is a complete portable page template`, async () => {
|
|
const markup = await readTemplate(name);
|
|
|
|
assertBalancedBlockMarkup(markup, name);
|
|
assert.equal((markup.match(/wp:template-part \{"slug":"header","tagName":"header"\}/g) ?? []).length, 1);
|
|
assert.equal((markup.match(/wp:template-part \{"slug":"footer","tagName":"footer"\}/g) ?? []).length, 1);
|
|
assert.equal((markup.match(/<main\b/g) ?? []).length, 1);
|
|
assert.equal((markup.match(/<\/main>/g) ?? []).length, 1);
|
|
assert.match(markup, /<main\b[^>]*\bid="chrnx-main"[^>]*>/);
|
|
assert.doesNotMatch(markup, /wp:(?:legacy-widget|widget-group)|<aside\b|sidebar/i);
|
|
assert.doesNotMatch(markup, /<\?php|https?:\/\//i);
|
|
});
|
|
}
|
|
|
|
test('home composes editorial sections in the approved order', async () => {
|
|
const markup = await readTemplate('home');
|
|
const orderedMarkers = [
|
|
'"slug":"header"',
|
|
'wp:pattern {"slug":"chrnx/home-intro"}',
|
|
'wp:chrnx/featured-stories',
|
|
'wp:chrnx/journal-stream',
|
|
'wp:pattern {"slug":"chrnx/home-projects"}',
|
|
'wp:pattern {"slug":"chrnx/home-music"}',
|
|
'wp:chrnx/latest-podcast',
|
|
'chrnx-home-about-preview',
|
|
'wp:chrnx/subscribe-cta',
|
|
'"slug":"footer"',
|
|
];
|
|
let previous = -1;
|
|
for (const marker of orderedMarkers) {
|
|
const index = markup.indexOf(marker);
|
|
assert.ok(index > previous, `${marker} must appear in the approved home order`);
|
|
previous = index;
|
|
}
|
|
});
|
|
|
|
test('single provides readable content, neutral metadata, and post-only components', async () => {
|
|
const markup = await readTemplate('single');
|
|
assert.match(markup, /chrnx-entry--single/);
|
|
assert.match(markup, /wp:post-title/);
|
|
assert.match(markup, /wp:post-terms \{"term":"chrnx_topic"/);
|
|
assert.match(markup, /wp:post-terms \{"term":"chrnx_language"/);
|
|
assert.match(markup, /wp:post-date/);
|
|
assert.match(markup, /wp:chrnx\/reading-time/);
|
|
assert.match(markup, /wp:post-featured-image/);
|
|
assert.match(markup, /wp:post-content/);
|
|
assert.match(markup, /wp:chrnx\/podcast-meta/);
|
|
assert.match(markup, /wp:chrnx\/related-posts/);
|
|
assert.match(markup, /wp:chrnx\/subscribe-cta/);
|
|
});
|
|
|
|
test('page remains a readable title and content shell without post metadata', async () => {
|
|
const markup = await readTemplate('page');
|
|
assert.match(markup, /chrnx-entry--page/);
|
|
assert.match(markup, /wp:post-title/);
|
|
assert.match(markup, /wp:post-content/);
|
|
assert.doesNotMatch(markup, /wp:post-(?:date|terms|featured-image)|wp:chrnx\/(?:podcast-meta|related-posts)/);
|
|
});
|
|
|
|
test('archive offers context, safe filters, stream, and a useful empty state', async () => {
|
|
const markup = await readTemplate('archive');
|
|
assert.match(markup, /wp:query-title/);
|
|
assert.match(markup, /wp:term-description/);
|
|
assert.match(markup, /wp:chrnx\/topic-hero/);
|
|
assert.match(markup, /wp:chrnx\/journal-stream/);
|
|
});
|
|
|
|
test('search offers search context, filters, and a Journal recovery path', async () => {
|
|
const markup = await readTemplate('search');
|
|
assert.match(markup, /wp:query-title \{"type":"search"/);
|
|
assert.match(markup, /wp:search/);
|
|
assert.match(markup, /wp:chrnx\/journal-stream/);
|
|
assert.match(markup, /wp:home-link/);
|
|
assert.doesNotMatch(markup, /"url":"\//);
|
|
});
|
|
|
|
test('404 offers concise recovery with search, Journal, and home links', async () => {
|
|
const markup = await readTemplate('404');
|
|
assert.match(markup, /Page not found/);
|
|
assert.match(markup, /wp:search/);
|
|
assert.match(markup, /wp:home-link/);
|
|
assert.match(markup, /wp:chrnx\/journal-link/);
|
|
assert.doesNotMatch(markup, /"url":"\//);
|
|
});
|
|
|
|
test('taxonomy-chrnx_project surfaces the project detail and its post stream', async () => {
|
|
const markup = await readTemplate('taxonomy-chrnx_project');
|
|
assert.match(markup, /wp:chrnx\/project-detail/);
|
|
assert.match(markup, /wp:chrnx\/journal-stream/);
|
|
});
|
|
|
|
test('taxonomy-chrnx_show surfaces show links and its episode stream', async () => {
|
|
const markup = await readTemplate('taxonomy-chrnx_show');
|
|
assert.match(markup, /wp:chrnx\/show-links/);
|
|
assert.match(markup, /wp:chrnx\/journal-stream/);
|
|
});
|