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>
91 lines
3.3 KiB
JavaScript
91 lines
3.3 KiB
JavaScript
// MITHOME-127: tests for scripts/check-indexability.sh against a local HTTP
|
|
// server that impersonates an indexable (production) or blocked (staging) site.
|
|
const { test, before, after } = require('node:test')
|
|
const assert = require('node:assert/strict')
|
|
const http = require('node:http')
|
|
const { spawn } = require('node:child_process')
|
|
const path = require('node:path')
|
|
|
|
const SCRIPT = path.join(__dirname, 'check-indexability.sh')
|
|
|
|
const SITES = {
|
|
indexable: {
|
|
'/robots.txt': 'User-Agent: *\nAllow: /\nDisallow: /admin\n\nSitemap: https://mozdit.hu/sitemap.xml\n',
|
|
'/sitemap.xml': '<urlset><url><loc>https://mozdit.hu/hu</loc></url><url><loc>https://mozdit.hu/en</loc></url></urlset>',
|
|
'/hu': '<html><head><title>mozdIT</title></head><body>ok</body></html>',
|
|
},
|
|
blocked: {
|
|
'/robots.txt': 'User-Agent: *\nDisallow: /\n',
|
|
'/sitemap.xml': '<urlset></urlset>',
|
|
'/hu': '<html><head><meta name="robots" content="noindex, nofollow"/></head><body>ok</body></html>',
|
|
},
|
|
// production build that wrongly got NEXT_PUBLIC_DEPLOY_ENV=staging for the page only
|
|
leakyNoindex: {
|
|
'/robots.txt': 'User-Agent: *\nAllow: /\n\nSitemap: https://mozdit.hu/sitemap.xml\n',
|
|
'/sitemap.xml': '<urlset><url><loc>https://mozdit.hu/hu</loc></url></urlset>',
|
|
'/hu': '<html><head><meta name="robots" content="noindex, nofollow"/></head></html>',
|
|
},
|
|
}
|
|
|
|
let server
|
|
let origin
|
|
|
|
before(async () => {
|
|
server = http.createServer((req, res) => {
|
|
const [, site, ...rest] = req.url.split('/')
|
|
const body = SITES[site]?.['/' + rest.join('/')]
|
|
res.writeHead(body === undefined ? 404 : 200)
|
|
res.end(body ?? 'not found')
|
|
})
|
|
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve))
|
|
origin = `http://127.0.0.1:${server.address().port}`
|
|
})
|
|
|
|
after(() => server.close())
|
|
|
|
function check(site, expect) {
|
|
return new Promise((resolve) => {
|
|
const child = spawn('bash', [SCRIPT, `${origin}/${site}`, expect])
|
|
let out = ''
|
|
child.stdout.on('data', (d) => (out += d))
|
|
child.stderr.on('data', (d) => (out += d))
|
|
child.on('close', (code) => resolve({ code, out }))
|
|
})
|
|
}
|
|
|
|
test('accepts an indexable production site', async () => {
|
|
const { code, out } = await check('indexable', 'indexable')
|
|
assert.equal(code, 0, out)
|
|
assert.match(out, /sitemap: 2 URL/)
|
|
})
|
|
|
|
test('accepts a blocked staging site', async () => {
|
|
assert.equal((await check('blocked', 'blocked')).code, 0)
|
|
})
|
|
|
|
test('fails when production is blocked, listing every problem', async () => {
|
|
const { code, out } = await check('blocked', 'indexable')
|
|
assert.equal(code, 1)
|
|
assert.match(out, /mindent tilt/)
|
|
assert.match(out, /noindex/)
|
|
assert.match(out, /sitemap üres/)
|
|
})
|
|
|
|
test('fails on a stray noindex even if robots.txt looks fine', async () => {
|
|
const { code, out } = await check('leakyNoindex', 'indexable')
|
|
assert.equal(code, 1)
|
|
assert.match(out, /noindex/)
|
|
})
|
|
|
|
test('fails when staging became indexable', async () => {
|
|
const { code } = await check('indexable', 'blocked')
|
|
assert.equal(code, 1)
|
|
})
|
|
|
|
test('returns 2 for bad usage or an unreachable site', async () => {
|
|
assert.equal((await check('indexable', 'maybe')).code, 2)
|
|
const missing = await check('missing', 'indexable')
|
|
assert.equal(missing.code, 2, missing.out)
|
|
assert.match(missing.out, /robots\.txt nem érhető el/)
|
|
})
|