theme.json shipped a palette entry with the slug "text", so WordPress
generated `.has-text-color { color: var(--wp--preset--color--text)
!important }`. The block editor puts that same class on any block given a
custom text colour, so the rule overrode every one of them site-wide with
the dark-theme foreground, unreadable in either theme. An !important
declaration beats an inline style, which is why the colour set on the
block never had a chance.
Rename the slug to "foreground". No published content used the class, for
the obvious reason that it never worked, so nothing has to be migrated.
A smoke test now rejects any palette slug that shadows an editor utility
class.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
164 lines
6.6 KiB
JavaScript
164 lines
6.6 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { access, readFile, readdir } from 'node:fs/promises';
|
|
import test from 'node:test';
|
|
|
|
const readProjectFile = (path) => readFile(new URL(`../../${path}`, import.meta.url), 'utf8');
|
|
|
|
test('Composer provides the PHPUnit Polyfills version required by WordPress tests', async () => {
|
|
const composer = JSON.parse(await readProjectFile('composer.json'));
|
|
const packageConfig = JSON.parse(await readProjectFile('package.json'));
|
|
|
|
assert.equal(composer['require-dev']['yoast/phpunit-polyfills'], '^2.0.5');
|
|
assert.equal(composer['require-dev']['phpunit/phpunit'], '^9.6');
|
|
assert.equal(
|
|
packageConfig.scripts['test:php'],
|
|
'wp-env run tests-cli --env-cwd=wp-content/themes/chrnx -- composer exec phpunit --',
|
|
);
|
|
});
|
|
|
|
test('PHPUnit discovers native test filenames without treating bootstrap as a test', async () => {
|
|
const config = await readProjectFile('phpunit.xml.dist');
|
|
|
|
assert.match(config, /<directory suffix="Test\.php">tests\/php<\/directory>/);
|
|
await access(new URL('../../tests/php/ThemeSetupTest.php', import.meta.url));
|
|
});
|
|
|
|
test('style.css declares the supported WordPress theme contract', async () => {
|
|
const stylesheet = await readProjectFile('style.css');
|
|
|
|
assert.match(stylesheet, /^Theme Name:\s*CHRNX$/m);
|
|
assert.match(stylesheet, /^Text Domain:\s*chrnx$/m);
|
|
assert.match(stylesheet, /^Requires at least:\s*6\.9$/m);
|
|
assert.match(stylesheet, /^Requires PHP:\s*8\.1$/m);
|
|
});
|
|
|
|
test('the stylesheet and PHP asset versions remain synchronized', async () => {
|
|
const stylesheet = await readProjectFile('style.css');
|
|
const functions = await readProjectFile('functions.php');
|
|
const stylesheetVersion = stylesheet.match(/^Version:\s*(\S+)$/m)?.[1];
|
|
const phpVersion = functions.match(/define\( 'CHRNX_VERSION', '([^']+)' \);/)?.[1];
|
|
|
|
assert.ok(stylesheetVersion, 'style.css must declare Version metadata');
|
|
assert.ok(phpVersion, 'functions.php must define the literal CHRNX_VERSION constant');
|
|
assert.equal(phpVersion, stylesheetVersion);
|
|
});
|
|
|
|
test('every block.json version matches CHRNX_VERSION so cached block assets bust', async () => {
|
|
// Block viewScript/style URLs are versioned from block.json, not
|
|
// CHRNX_VERSION. Letting them drift served stale JS from browser cache.
|
|
const functions = await readProjectFile('functions.php');
|
|
const phpVersion = functions.match(/define\( 'CHRNX_VERSION', '([^']+)' \);/)?.[1];
|
|
assert.ok(phpVersion, 'functions.php must define the literal CHRNX_VERSION constant');
|
|
|
|
const blocksDir = new URL('../../blocks/', import.meta.url);
|
|
const names = (await readdir(blocksDir, { withFileTypes: true }))
|
|
.filter((entry) => entry.isDirectory())
|
|
.map((entry) => entry.name)
|
|
.sort();
|
|
assert.ok(names.length > 0, 'blocks/ must contain block directories');
|
|
|
|
for (const name of names) {
|
|
const block = JSON.parse(await readProjectFile(`blocks/${name}/block.json`));
|
|
assert.equal(block.version, phpVersion, `blocks/${name}/block.json version`);
|
|
}
|
|
});
|
|
|
|
test('no shipped runtime file points at an unshipped design master', async () => {
|
|
// The package excludes assets/images/*.png|jpeg because every image is served
|
|
// from assets/images/generated. A direct reference would 404 once installed.
|
|
const roots = ['inc', 'blocks', 'patterns', 'parts', 'templates', 'assets/css'];
|
|
const offenders = [];
|
|
const walk = async (dir) => {
|
|
for (const entry of await readdir(new URL(`../../${dir}/`, import.meta.url), { withFileTypes: true })) {
|
|
const path = `${dir}/${entry.name}`;
|
|
if (entry.isDirectory()) {
|
|
await walk(path);
|
|
continue;
|
|
}
|
|
if (!/\.(php|css|html|json)$/.test(entry.name)) {
|
|
continue;
|
|
}
|
|
const source = await readProjectFile(path);
|
|
// Anything under generated/ is shipped; a bare master path is not.
|
|
const matches = source.match(/assets\/images\/(?!generated\/)[A-Za-z0-9._-]+\.(?:png|jpe?g)/g);
|
|
if (matches) {
|
|
offenders.push(`${path}: ${[...new Set(matches)].join(', ')}`);
|
|
}
|
|
}
|
|
};
|
|
for (const root of roots) {
|
|
await walk(root);
|
|
}
|
|
|
|
assert.deepEqual(offenders, [], `runtime files reference unshipped masters:\n${offenders.join('\n')}`);
|
|
});
|
|
|
|
test('theme.json declares the v3 schema and layout widths', async () => {
|
|
const theme = JSON.parse(await readProjectFile('theme.json'));
|
|
|
|
assert.equal(theme.$schema, 'https://schemas.wp.org/wp/6.9/theme.json');
|
|
assert.equal(theme.version, 3);
|
|
assert.equal(theme.settings.layout.contentSize, '720px');
|
|
assert.equal(theme.settings.layout.wideSize, '1120px');
|
|
});
|
|
|
|
test('theme.json exposes the complete dark and warm-light palette with stable semantic slugs', async () => {
|
|
const theme = JSON.parse(await readProjectFile('theme.json'));
|
|
const palette = Object.fromEntries(
|
|
theme.settings.color.palette.map(({ slug, color }) => [slug, color.toUpperCase()]),
|
|
);
|
|
const expectedTokens = {
|
|
night: '#0D1117',
|
|
panel: '#161B22',
|
|
violet: '#7C6CF0',
|
|
green: '#5FB88A',
|
|
foreground: '#E6EDF3',
|
|
muted: '#8B949E',
|
|
paper: '#F6F2E9',
|
|
surface: '#FFFDF7',
|
|
ink: '#25221F',
|
|
'light-muted': '#625C54',
|
|
'light-violet': '#674CA4',
|
|
'light-green': '#327854',
|
|
border: '#DED6C7',
|
|
};
|
|
|
|
assert.deepEqual(palette, expectedTokens);
|
|
});
|
|
|
|
test('no palette slug collides with a block editor utility class', async () => {
|
|
const theme = JSON.parse(await readProjectFile('theme.json'));
|
|
/*
|
|
* WordPress emits `.has-<slug>-color { color: ... !important }` for every
|
|
* palette entry. The editor adds the class `has-text-color` to any block
|
|
* carrying a custom text colour, so a slug named "text" produced a rule
|
|
* that overrode every custom colour on the site with the preset value.
|
|
*/
|
|
const reserved = new Set(['text', 'background', 'link']);
|
|
const collisions = theme.settings.color.palette
|
|
.map(({ slug }) => slug)
|
|
.filter((slug) => reserved.has(slug));
|
|
|
|
assert.deepEqual(collisions, []);
|
|
});
|
|
|
|
test('the local Zen Maru Gothic files and license are present', async () => {
|
|
await Promise.all([
|
|
'assets/fonts/zen-maru-gothic-latin-500.woff2',
|
|
'assets/fonts/zen-maru-gothic-latin-700.woff2',
|
|
'assets/fonts/OFL.txt',
|
|
].map((path) => access(new URL(`../../${path}`, import.meta.url))));
|
|
});
|
|
|
|
test('the index template has header, semantic query content, and footer regions', async () => {
|
|
const template = await readProjectFile('templates/index.html');
|
|
|
|
assert.match(template, /<!-- wp:template-part \{"slug":"header","tagName":"header"\} \/-->/);
|
|
assert.match(template, /<!-- wp:group \{"tagName":"main"[^>]*-->/);
|
|
// index is the last-resort fallback; it lists posts through the same
|
|
// stream every other archive uses, not an unstyled core query loop.
|
|
assert.match(template, /<!-- wp:query-title\b/);
|
|
assert.match(template, /<!-- wp:chrnx\/journal-stream \/-->/);
|
|
assert.match(template, /<!-- wp:template-part \{"slug":"footer","tagName":"footer"\} \/-->/);
|
|
});
|