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 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(/]*>/gi) ?? []; for (const tag of linkTags) { assert.doesNotMatch( tag, /fonts\.googleapis\.com|fonts\.gstatic\.com/i, `${route}: must not contain external Google Fonts tag: ${tag}`, ); } } }, ); await t.test( 'Criterion 2a: dist/404.html exists and includes shared
and