Files
Niklas MischkulnigandGitHub db1f3a64da Fix duplicate static files in adapter (#95681)
When using `nextConfig.i18n`, then static files for `404.html` and
`500.html` were added multiple times to the list.

These duplicate entries in `outputs.staticFiles` ended up causing race
conditions in the Vercel adapter because the same output file path was
written concurrently by multiple file operations.
2026-07-13 09:44:27 +02:00

53 lines
1.9 KiB
TypeScript

import { nextTestSetup } from 'e2e-utils'
import type { NextAdapter } from 'next'
describe('adapter config with i18n routes', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('does not localize dynamic Pages API routes', async () => {
const { outputs, routing }: Parameters<NextAdapter['onBuildComplete']>[0] =
await next.readJSON('build-complete.json')
const apiOutput = outputs.pagesApi.find(
(output) => output.pathname === '/api/proxy/[[...slug]]'
)
const apiRoute = routing.dynamicRoutes.find(
(route) => route.source === '/api/proxy/[[...slug]]'
)
const pageRoute = routing.dynamicRoutes.find(
(route) => route.source === '/blog/[slug]'
)
expect(apiOutput).toBeDefined()
expect(apiRoute).toBeDefined()
expect(apiRoute?.sourceRegex).not.toContain('nextLocale')
expect(apiRoute?.destination).toBe(
'/api/proxy/[[...slug]]?nxtPslug=$nxtPslug'
)
expect(pageRoute).toBeDefined()
expect(pageRoute?.sourceRegex).toContain('nextLocale')
expect(pageRoute?.destination).toBe(
'/$nextLocale/blog/[slug]?nxtPslug=$nxtPslug'
)
})
it('does not emit outputs multiple times for a given pathname', async () => {
const { outputs }: Parameters<NextAdapter['onBuildComplete']>[0] =
await next.readJSON('build-complete.json')
const pathnameSet = (f) => new Set(f.map((o) => o.pathname))
expect(pathnameSet(outputs.pages).size).toBe(outputs.pages.length)
expect(pathnameSet(outputs.appPages).size).toBe(outputs.appPages.length)
expect(pathnameSet(outputs.pagesApi).size).toBe(outputs.pagesApi.length)
expect(pathnameSet(outputs.appRoutes).size).toBe(outputs.appRoutes.length)
expect(pathnameSet(outputs.prerenders).size).toBe(outputs.prerenders.length)
expect(pathnameSet(outputs.staticFiles).size).toBe(
outputs.staticFiles.length
)
})
})