Files
hanzo.ai/e2e/unit/robots.spec.ts

27 lines
1011 B
TypeScript

import { test, expect } from '@playwright/test'
import { readdirSync, readFileSync, statSync } from 'node:fs'
import { join } from 'node:path'
/**
* NO PAGE DECLARES ITS OWN ROBOTS TAG.
*
* lib/publish decides which routes are withheld from indexing, and
* scripts/noindex.mjs writes that tag into the export — refusing, and failing
* the build, on a page that already carries one. A `robots` field in a page's
* metadata is that second declaration; this finds it in the source, in a
* second, instead of at the end of the export.
*/
function files(dir: string): string[] {
return readdirSync(dir).flatMap((name) => {
const p = join(dir, name)
if (statSync(p).isDirectory()) return files(p)
return /(page|layout)\.tsx?$/.test(name) ? [p] : []
})
}
test('no page or layout declares robots in its metadata', () => {
const declared = files(join(import.meta.dirname, '..', '..', 'app')).filter((f) => /^\s*robots\s*:/m.test(readFileSync(f, 'utf8')))
expect(declared).toEqual([])
})