flnxi-Wu/lib/__tests__/production-route-guard.test.ts
2026-05-28 17:47:49 +08:00

23 lines
659 B
TypeScript

import fs from 'fs'
import path from 'path'
const rootDir = path.resolve(__dirname, '..', '..')
function collectRouteFiles(dir: string): string[] {
if (!fs.existsSync(dir)) return []
return fs.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
const fullPath = path.join(dir, entry.name)
if (entry.isDirectory()) return collectRouteFiles(fullPath)
return entry.name === 'route.ts' ? [fullPath] : []
})
}
describe('生产路由边界', () => {
it('不应保留公开 debug API 路由', () => {
const debugRoutes = collectRouteFiles(path.join(rootDir, 'app', 'api', 'debug'))
expect(debugRoutes).toEqual([])
})
})