Unverified Commit cef5745b authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

test: cover analyzer export for parallel-slot catch-alls

Co-authored-by: 's avatarWill Binns-Smith <755844+wbinnssmith@users.noreply.github.com>
parent 80d27553
export default function Page() {
return <p>Children catch-all</p>
}
export default function CatchAll() {
return null
}
export default function Default() {
return null
}
export default function Layout({
children,
modal,
}: {
children: React.ReactNode
modal: React.ReactNode
}) {
return (
<>
{children}
{modal}
</>
)
}
// Give the modal catch-all a complete route without a children-slot catch-all.
export default function Page() {
return <p>Other children page</p>
}
export default function Page() {
return <p>Parallel slots</p>
}
...@@ -84,8 +84,11 @@ const EXPECTED_ROUTES = [ ...@@ -84,8 +84,11 @@ const EXPECTED_ROUTES = [
'/_global-error', '/_global-error',
'/_not-found', '/_not-found',
'/api/ping', '/api/ping',
'/children-catch-all/[...catchAll]',
'/legacy', '/legacy',
'/meta/icon', '/meta/icon',
'/parallel-slots',
'/parallel-slots/other',
'/sitemap.xml', '/sitemap.xml',
].sort() ].sort()
...@@ -267,23 +270,37 @@ describe('next analyze', () => { ...@@ -267,23 +270,37 @@ describe('next analyze', () => {
for (const record of records) for (const record of records)
expect(record).not.toHaveProperty('route_index') expect(record).not.toHaveProperty('route_index')
// Every summarized route, including metadata routes, is exported. // Every summarized route, including metadata routes, is exported.
expect(exportedRoutes(records)).toEqual(readRoutes(snapshotDir)) const routes = readRoutes(snapshotDir)
expect([...readRoutes(snapshotDir)].sort()).toEqual(EXPECTED_ROUTES) expect(exportedRoutes(records)).toEqual(routes)
expect([...routes].sort()).toEqual(EXPECTED_ROUTES)
// A slot-only catch-all is discovered on disk but has no standalone data.
// A catch-all in the children slot must still be indexed and exported.
const slotOnlyCatchAll = '/parallel-slots/[...catchAll]'
const childrenCatchAll = '/children-catch-all/[...catchAll]'
expect(routes).toContain('/parallel-slots')
expect(routes).not.toContain(slotOnlyCatchAll)
expect(routes).toContain(childrenCatchAll)
for (const directory of [path.join(analyzeDir, 'data'), snapshotDir]) {
expect(existsSync(routeDataFile(directory, slotOnlyCatchAll))).toBe(false)
expect(existsSync(routeDataFile(directory, childrenCatchAll))).toBe(true)
}
expect( expect(
JSON.parse(readFileSync(path.join(snapshotDir, 'metadata.json'), 'utf8')) JSON.parse(readFileSync(path.join(snapshotDir, 'metadata.json'), 'utf8'))
.routeCount .routeCount
).toBe(readRoutes(snapshotDir).length) ).toBe(routes.length)
// route-summaries.json is the only route index. // route-summaries.json is the only route index.
expect(existsSync(path.join(snapshotDir, 'routes.json'))).toBe(false) expect(existsSync(path.join(snapshotDir, 'routes.json'))).toBe(false)
expect(existsSync(path.join(analyzeDir, 'data/routes.json'))).toBe(false) expect(existsSync(path.join(analyzeDir, 'data/routes.json'))).toBe(false)
// A stale routes.json left by older captures, with routes-manifest names // A stale routes.json left by older captures, with metadata and slot-only
// that have no data, is ignored. // routes-manifest names that have no data, is ignored.
const legacyRoutesFile = path.join(snapshotDir, 'routes.json') const legacyRoutesFile = path.join(snapshotDir, 'routes.json')
try { try {
writeFileSync( writeFileSync(
legacyRoutesFile, legacyRoutesFile,
JSON.stringify(['/', '/meta/icon/[__metadata_id__]']) JSON.stringify(['/', '/meta/icon/[__metadata_id__]', slotOnlyCatchAll])
) )
const legacy = await next.runCommand([ const legacy = await next.runCommand([
'analyze', 'analyze',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment