Files
chrnx-dev-wp/tests/smoke/theme-contract.test.mjs
T

97 lines
3.8 KiB
JavaScript

import assert from 'node:assert/strict';
import { access, readFile } 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('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',
text: '#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('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"[^>]*-->/);
assert.match(template, /<!-- wp:query\b/);
assert.match(template, /<!-- wp:post-template -->/);
assert.match(template, /<!-- wp:post-(?:content|excerpt)\b/);
assert.match(template, /<!-- wp:template-part \{"slug":"footer","tagName":"footer"\} \/-->/);
});