mirror of
https://github.com/corazoncp/corazoncp-landing.git
synced 2026-12-01 04:30:31 +00:00
* test(wpo): add Red contract tests for self-hosted woff2, 404.html, twitter:card, img dims, and view transitions - Assert self-hosted .woff2 fonts in public/fonts/, @font-face in built CSS, and zero Google Fonts links - Assert dist/404.html with shared partials, zero inline scripts, and return CTA to / - Assert twitter:card on all 4 routes, numeric width/height on all <img> tags, @view-transition, and brand hover * perf(wpo): self-host woff2 fonts, add 404.html, explicit img dims, twitter:card, and view transitions - Self-host 5 latin .woff2 font files (176 KB total) in public/fonts/ with @font-face in src/style.css and remove Google Fonts links - Add static 404.html with shared partials and register in vite.config.ts - Add twitter:card metadata across all 4 routes and explicit width/height on logo.png and all 8 index.html images - Add @view-transition (prefers-reduced-motion: no-preference), brand hover state, arrow motion on solid CTAs, and reconcile services-catalog.test.js
240 lines
7.7 KiB
JavaScript
240 lines
7.7 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import test from 'node:test';
|
|
|
|
const ROUTES = [
|
|
'dist/index.html',
|
|
'dist/kundalini/index.html',
|
|
'dist/volver-a-ti/index.html',
|
|
'dist/descargo/index.html',
|
|
];
|
|
|
|
const ALL_BUILT_HTML = [...ROUTES, 'dist/404.html'];
|
|
|
|
function readHtml(filePath) {
|
|
return fs.readFileSync(path.resolve(filePath), 'utf-8');
|
|
}
|
|
|
|
function readBuiltCss() {
|
|
const assetsDir = path.resolve('dist/assets');
|
|
const cssFiles = fs.readdirSync(assetsDir).filter((file) => file.endsWith('.css'));
|
|
assert.ok(cssFiles.length > 0, 'dist/assets must contain at least one built CSS file');
|
|
return cssFiles.map((file) => fs.readFileSync(path.join(assetsDir, file), 'utf-8')).join('\n');
|
|
}
|
|
|
|
function extractBalancedBlock(css, startIndex) {
|
|
const openBrace = css.indexOf('{', startIndex);
|
|
if (openBrace === -1) {
|
|
return undefined;
|
|
}
|
|
let depth = 0;
|
|
for (let i = openBrace; i < css.length; i++) {
|
|
if (css[i] === '{') {
|
|
depth += 1;
|
|
} else if (css[i] === '}') {
|
|
depth -= 1;
|
|
if (depth === 0) {
|
|
return css.slice(openBrace + 1, i);
|
|
}
|
|
}
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
test('Issue #12 Acceptance Criteria: Self-hosted fonts, 404.html, meta/img dimensions, view transitions', async (t) => {
|
|
await t.test(
|
|
'Criterion 1a: public/fonts/ contains .woff2 files for Playfair Display, Cormorant Garamond, and Raleway',
|
|
() => {
|
|
const fontsDir = path.resolve('public/fonts');
|
|
assert.ok(fs.existsSync(fontsDir), 'public/fonts/ directory must exist');
|
|
|
|
const woff2Files = fs
|
|
.readdirSync(fontsDir)
|
|
.filter((file) => file.toLowerCase().endsWith('.woff2'));
|
|
assert.ok(woff2Files.length > 0, 'public/fonts/ must contain .woff2 files');
|
|
|
|
const joined = woff2Files.join('\n').toLowerCase();
|
|
assert.match(
|
|
joined,
|
|
/playfair-display/,
|
|
'public/fonts/ must include Playfair Display .woff2',
|
|
);
|
|
assert.match(
|
|
joined,
|
|
/cormorant-garamond/,
|
|
'public/fonts/ must include Cormorant Garamond .woff2',
|
|
);
|
|
assert.match(joined, /raleway/, 'public/fonts/ must include Raleway .woff2');
|
|
},
|
|
);
|
|
|
|
await t.test(
|
|
'Criterion 1b: built CSS declares @font-face rules pointing to /fonts/*.woff2',
|
|
() => {
|
|
const css = readBuiltCss();
|
|
const fontFaceMatches = css.match(/@font-face\s*\{[^}]*\}/gi) ?? [];
|
|
assert.ok(fontFaceMatches.length > 0, 'built CSS must declare @font-face rules');
|
|
|
|
const hasLocalWoff2 = fontFaceMatches.some((rule) =>
|
|
/url\(["']?\/fonts\/[^"')]+?\.woff2["']?\)/i.test(rule),
|
|
);
|
|
assert.ok(hasLocalWoff2, 'built CSS @font-face rules must point to /fonts/*.woff2');
|
|
},
|
|
);
|
|
|
|
await t.test(
|
|
'Criterion 1c: zero built HTML files contain fonts.googleapis.com or fonts.gstatic.com <link> tags',
|
|
() => {
|
|
for (const route of ALL_BUILT_HTML) {
|
|
const resolved = path.resolve(route);
|
|
if (!fs.existsSync(resolved)) {
|
|
continue;
|
|
}
|
|
const html = fs.readFileSync(resolved, 'utf-8');
|
|
const linkTags = html.match(/<link\b[^>]*>/gi) ?? [];
|
|
for (const tag of linkTags) {
|
|
assert.doesNotMatch(
|
|
tag,
|
|
/fonts\.googleapis\.com|fonts\.gstatic\.com/i,
|
|
`${route}: must not contain external Google Fonts <link> tag: ${tag}`,
|
|
);
|
|
}
|
|
}
|
|
},
|
|
);
|
|
|
|
await t.test(
|
|
'Criterion 2a: dist/404.html exists and includes shared <header> and <footer> partials',
|
|
() => {
|
|
const notFoundPath = path.resolve('dist/404.html');
|
|
assert.ok(fs.existsSync(notFoundPath), 'dist/404.html must exist');
|
|
|
|
const html = fs.readFileSync(notFoundPath, 'utf-8');
|
|
assert.match(html, /<header\b[^>]*>/i, 'dist/404.html must include shared <header>');
|
|
assert.match(html, /<footer\b[^>]*>/i, 'dist/404.html must include shared <footer>');
|
|
},
|
|
);
|
|
|
|
await t.test(
|
|
'Criterion 2b: dist/404.html has zero inline <script> blocks or on*= handlers and links back to /',
|
|
() => {
|
|
const html = readHtml('dist/404.html');
|
|
const scriptTags = html.match(/<script\b[^>]*>/gi) ?? [];
|
|
for (const tag of scriptTags) {
|
|
assert.match(
|
|
tag,
|
|
/\bsrc\s*=/i,
|
|
`dist/404.html must not contain inline <script> blocks: ${tag}`,
|
|
);
|
|
}
|
|
|
|
assert.doesNotMatch(
|
|
html,
|
|
/<[a-z][^>]*\son[a-z]+\s*=/i,
|
|
'dist/404.html must not contain inline on*= event handlers',
|
|
);
|
|
|
|
assert.match(
|
|
html,
|
|
/<a\b[^>]*\bhref="\/"[^>]*>/i,
|
|
'dist/404.html must include a link back to /',
|
|
);
|
|
},
|
|
);
|
|
|
|
await t.test(
|
|
'Criterion 3a: all 4 routes include <meta name="twitter:card" content="summary_large_image">',
|
|
() => {
|
|
for (const route of ROUTES) {
|
|
const html = readHtml(route);
|
|
const metaTags = html.match(/<meta\b[^>]*>/gi) ?? [];
|
|
const hasTwitterCard = metaTags.some(
|
|
(tag) =>
|
|
/\bname="twitter:card"/i.test(tag) && /\bcontent="summary_large_image"/i.test(tag),
|
|
);
|
|
assert.ok(
|
|
hasTwitterCard,
|
|
`${route}: must include <meta name="twitter:card" content="summary_large_image">`,
|
|
);
|
|
}
|
|
},
|
|
);
|
|
|
|
await t.test(
|
|
'Criterion 3b: every <img> tag across all built HTML pages has explicit numeric width and height attributes',
|
|
() => {
|
|
for (const route of ALL_BUILT_HTML) {
|
|
const resolved = path.resolve(route);
|
|
if (!fs.existsSync(resolved)) {
|
|
continue;
|
|
}
|
|
const html = fs.readFileSync(resolved, 'utf-8');
|
|
const imgTags = html.match(/<img\b[^>]*>/gi) ?? [];
|
|
assert.ok(imgTags.length > 0 || route === 'dist/404.html', `${route}: expected <img> tags`);
|
|
|
|
for (const img of imgTags) {
|
|
assert.match(
|
|
img,
|
|
/\bwidth="\d+"/i,
|
|
`${route}: <img> must have explicit numeric width attribute: ${img}`,
|
|
);
|
|
assert.match(
|
|
img,
|
|
/\bheight="\d+"/i,
|
|
`${route}: <img> must have explicit numeric height attribute: ${img}`,
|
|
);
|
|
}
|
|
}
|
|
},
|
|
);
|
|
|
|
await t.test(
|
|
'Criterion 4a: built CSS includes @view-transition (navigation: auto) inside @media (prefers-reduced-motion: no-preference)',
|
|
() => {
|
|
const css = readBuiltCss();
|
|
const mediaRegex = /@media\s*\(\s*prefers-reduced-motion\s*:\s*no-preference\s*\)/gi;
|
|
let found = false;
|
|
|
|
for (const match of css.matchAll(mediaRegex)) {
|
|
const block = extractBalancedBlock(css, match.index);
|
|
if (block && /@view-transition\s*\{[^}]*\bnavigation\s*:\s*auto\b/i.test(block)) {
|
|
found = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
assert.ok(
|
|
found,
|
|
'built CSS must include @view-transition { navigation: auto } inside @media (prefers-reduced-motion: no-preference)',
|
|
);
|
|
},
|
|
);
|
|
|
|
await t.test(
|
|
'Criterion 4b: header brand link a[href="/"] includes a hover: transition class',
|
|
() => {
|
|
for (const route of ROUTES) {
|
|
const html = readHtml(route);
|
|
const headerMatch = html.match(/<header\b[^>]*>([\s\S]*?)<\/header>/i);
|
|
assert.ok(headerMatch, `${route}: must contain <header>`);
|
|
|
|
const brandLink = headerMatch[1].match(/<a\b[^>]*\bhref="\/"[^>]*>/i)?.[0];
|
|
assert.ok(brandLink, `${route}: <header> must contain <a href="/">`);
|
|
|
|
const classAttr = brandLink.match(/\bclass="([^"]*)"/i)?.[1] ?? '';
|
|
assert.match(
|
|
classAttr,
|
|
/(?:^|\s)hover:/,
|
|
`${route}: header a[href="/"] must include a hover: class`,
|
|
);
|
|
assert.match(
|
|
classAttr,
|
|
/\btransition\b/,
|
|
`${route}: header a[href="/"] must include a transition class`,
|
|
);
|
|
}
|
|
},
|
|
);
|
|
});
|