import assert from 'node:assert/strict'; import fs from 'node:fs'; const base = process.env.BLOG_TEST_URL || 'http://127.0.0.1:3108'; const indexing = process.env.BLOG_INDEXING_ENABLED === 'true'; const approvedInventory = JSON.parse(fs.readFileSync('src/content/blog/approved-inventory.json', 'utf8')); const all = JSON.parse(fs.readFileSync('src/content/blog/articles.json', 'utf8')); const visible = all.filter(a => !indexing || a.published); const published = all.filter(a => a.published); const pathFor = a => `${a.locale === 'en' ? '' : `/${a.locale}`}/blogs/${a.slug}`; const indexFor = locale => `${locale === 'en' ? '' : `/${locale}`}/blogs`; let checked = 0; for (const locale of new Set(visible.map(a => a.locale))) { const records = [{ locale, path: indexFor(locale) }, ...visible.filter(a => a.locale === locale).map(a => ({ ...a, path: pathFor(a) }))]; for (const a of records) { const response = await fetch(`${base}${a.path}`); assert.equal(response.status, 200, a.path); assert.equal(response.headers.get('x-robots-tag'), null, `Private route header leaked onto blog: ${a.path}`); const html = await response.text(); assert(html.includes(`[^<]+STRATA<\/title>/.test(html), `Missing title: ${a.path}`); assert(/name="description" content="[^"]+"/.test(html)); assert(html.includes(`property="og:url" content="https://text.skin${a.path}"`)); const variants = a.id ? published.filter(b => b.id === a.id) : [...new Set(published.map(b => b.locale))].map(locale => ({ locale })); for (const b of variants) assert(html.includes(`hrefLang="${b.locale}" href="https://text.skin${b.id ? pathFor(b) : indexFor(b.locale)}"`), `Missing SEO alternate ${a.path} → ${b.locale}`); const alternateCount = (html.match(/rel="alternate" hrefLang=/g) || []).length; assert.equal(alternateCount, variants.length + (variants.some(b => b.locale === 'en') ? 1 : 0), `Unexpected alternate: ${a.path}`); assert(!html.includes('nav.blogs'), 'Untranslated key'); if (a.id) { assert(/

.+?<\/h1>/.test(html), 'Missing server-rendered heading'); assert(/

.+?<\/h2>/.test(html), 'Missing server-rendered article body'); const schema = JSON.parse(html.match(/