Files
websitedev/proto/e2e/production-seo.spec.ts
T
Do SikiandClaude Opus 5.5 dc7a777d9f feat(deploy): indexability guard and production SEO launch suite (MITHOME-127)
The staging noindex (MITHOME-116) hinges on a build variable; leaking it
into production would silently drop the site from Google. deploy.sh now
refuses to build production when NEXT_PUBLIC_DEPLOY_ENV=staging is set,
and after every deploy runs scripts/check-indexability.sh, expecting an
indexable production and a blocked staging (node tests cover both ways,
stray noindex and unreachable endpoints; added to pre-deploy tests).

A separate Playwright project, production-seo (npm run
test:seo:production), checks robots.txt, that all 12 sitemap URLs are
final/indexable with self canonicals and sitemap hreflangs, SSR content
and links, the / -> /hu redirect and real 404s; host redirects are gated
until the production domain is live. Verified on a production-mode build
of a staging DB copy (5 passed) and failing as expected against staging.

eslint now ignores generated test output (playwright-report, test-results,
coverage), which broke the pre-deploy lint after local e2e runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 13:23:23 +02:00

74 lines
3.4 KiB
TypeScript

import { expect, test, type APIRequestContext } from '@playwright/test'
/**
* MITHOME-127 — production launch SEO checks (run at go-live and after every
* production release): `BASE_URL=https://mozdit.hu npm run test:seo:production`.
*
* The site must be indexable, every sitemap URL must be final (200, no
* redirect), canonical/hreflang must point at those final URLs, and content +
* internal links must be in the server-rendered HTML (no JS needed).
* Host-level redirects (http→https, www→apex) are nginx's job (MITHOME-15):
* set SEO_CHECK_HOST_REDIRECTS=1 once the production domain is live.
*/
const text = async (request: APIRequestContext, path: string) => {
const response = await request.get(path, { maxRedirects: 0 })
expect(response.status(), `${path} status`).toBe(200)
return response.text()
}
const locs = (xml: string) => [...xml.matchAll(/<loc>([^<]+)<\/loc>/g)].map((m) => m[1])
const attr = (html: string, pattern: RegExp) => html.match(pattern)?.[1]
test('robots.txt allows crawling and points to the sitemap', async ({ request, baseURL }) => {
const robots = await text(request, '/robots.txt')
expect(robots).not.toMatch(/^Disallow:\s*\/\s*$/im)
expect(robots).toContain(`Sitemap: ${baseURL}/sitemap.xml`)
})
test('every sitemap URL is final, indexable and correctly annotated', async ({ request, baseURL }) => {
const urls = locs(await text(request, '/sitemap.xml'))
expect(urls).toHaveLength(12)
for (const url of urls) {
expect(url.startsWith(`${baseURL}/`), `${url} is on ${baseURL}`).toBe(true)
const html = await text(request, url)
expect(html, `${url} has no noindex`).not.toMatch(/<meta[^>]*name="robots"[^>]*noindex/i)
expect(attr(html, /<link rel="canonical" href="([^"]+)"/), `${url} canonical`).toBe(url)
for (const lang of ['hu', 'en', 'x-default']) {
const alternate = attr(html, new RegExp(`<link rel="alternate" hrefLang="${lang}" href="([^"]+)"`))
expect(urls, `${url} hreflang ${lang} → ${alternate}`).toContain(alternate)
}
}
})
test('content and internal links are in the server-rendered HTML', async ({ request }) => {
const html = await text(request, '/hu')
expect(html).toMatch(/<h1[^>]*>[^<]+/)
for (const path of ['/hu/rolunk', '/hu/szolgaltatasok', '/hu/kapcsolat', '/en']) {
expect(html, `link to ${path}`).toContain(`href="${path}"`)
}
})
test('the site root redirects to /hu in one step', async ({ request }) => {
const response = await request.get('/', { maxRedirects: 0 })
expect([301, 302, 307, 308]).toContain(response.status())
expect(new URL(response.headers()['location'], 'http://x').pathname).toBe('/hu')
})
test('unknown pages return a real 404', async ({ request }) => {
const response = await request.get('/hu/nincs-ilyen-oldal', { maxRedirects: 0 })
expect(response.status()).toBe(404)
})
test('host variants redirect to the canonical origin in one step', async ({ request, baseURL }) => {
test.skip(!process.env.SEO_CHECK_HOST_REDIRECTS, 'nginx host redirects are checked once the production domain is live (MITHOME-15)')
const canonical = new URL(baseURL!)
const variants = [`http://${canonical.host}/hu`, `https://www.${canonical.host}/hu`]
for (const variant of variants) {
const response = await request.get(variant, { maxRedirects: 0 })
expect([301, 308], `${variant} status`).toContain(response.status())
expect(response.headers()['location'], `${variant} target`).toBe(`${canonical.origin}/hu`)
}
})