mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
### What? Propagate edge runtime preferredRegion metadata into adapter outputs and add adapter-config coverage for an edge app route. ### Why? Adapters need access to preferred region metadata from edge outputs when generating provider-specific deployment output. ### How? Copy edge function regions into output.config.preferredRegion and assert the adapter build-complete output for a fixture route with preferredRegion set to cdg1. ### Verification - `pnpm --filter=next build` - `NEXT_TEST_PREFER_OFFLINE=1 pnpm test-start-webpack test/production/adapter-config/adapter-config.test.ts` <!-- NEXT_JS_LLM_PR -->
98 lines
2.7 KiB
TypeScript
98 lines
2.7 KiB
TypeScript
import fs from 'fs'
|
|
import type { NextAdapter } from 'next'
|
|
import { nextTestSetup } from 'e2e-utils'
|
|
import { version as nextVersion } from 'next/package.json'
|
|
|
|
process.env.TEST_EXPORT = '1'
|
|
|
|
describe('adapter-config export', () => {
|
|
const { next } = nextTestSetup({
|
|
files: __dirname,
|
|
skipStart: true,
|
|
})
|
|
|
|
it('should call onBuildComplete with correct context', async () => {
|
|
const nonExportFiles = [
|
|
'app/node-app/page.tsx',
|
|
'app/node-route/route.ts',
|
|
'app/edge-route/route.ts',
|
|
'app/preferred-region/route.ts',
|
|
'app/isr-route/route.ts',
|
|
'app/isr-route/[slug]/route.ts',
|
|
'app/edge-app/page.tsx',
|
|
'pages/api/edge-pages.ts',
|
|
'pages/api/node-pages.ts',
|
|
'pages/edge-pages/index.tsx',
|
|
'pages/node-pages/index.tsx',
|
|
'app/node-app/[slug]/page.tsx',
|
|
'app/node-app/@dialog/default.tsx',
|
|
'app/node-app/@dialog/[slug]/page.tsx',
|
|
]
|
|
|
|
for (const file of nonExportFiles) {
|
|
await next.remove(file)
|
|
}
|
|
|
|
await next.build()
|
|
expect(next.cliOutput).toContain('onBuildComplete called')
|
|
|
|
const {
|
|
outputs,
|
|
routing,
|
|
config,
|
|
...ctx
|
|
}: Parameters<NextAdapter['onBuildComplete']>[0] = await next.readJSON(
|
|
'build-complete.json'
|
|
)
|
|
|
|
for (const field of ['distDir', 'projectDir', 'repoRoot']) {
|
|
expect(ctx[field]).toBeString()
|
|
|
|
if (!fs.existsSync(ctx[field])) {
|
|
throw new Error(
|
|
`Invalid dir value provided for ${field} value ${ctx[field]}`
|
|
)
|
|
}
|
|
}
|
|
|
|
expect(ctx.nextVersion).toBe(nextVersion)
|
|
expect(ctx.projectDir).toBe(next.testDir)
|
|
expect(config?.basePath).toBe('/docs')
|
|
|
|
const combinedRouteOutputs = [
|
|
...outputs.appPages,
|
|
...outputs.appRoutes,
|
|
...outputs.pages,
|
|
...outputs.pagesApi,
|
|
]
|
|
|
|
expect(outputs.middleware).toBeFalsy()
|
|
expect(outputs.prerenders).toEqual([])
|
|
expect(combinedRouteOutputs).toEqual([])
|
|
|
|
for (const output of outputs.staticFiles) {
|
|
expect(output.id).toBeTruthy()
|
|
|
|
if (output.filePath.endsWith('.html')) {
|
|
expect(output.pathname.endsWith('.html')).toBe(false)
|
|
}
|
|
expect(output.pathname).toStartWith('/docs/')
|
|
|
|
const stats = await fs.promises.stat(output.filePath)
|
|
expect(stats.isFile()).toBe(true)
|
|
}
|
|
|
|
expect(routing).toEqual({
|
|
beforeMiddleware: expect.toBeArray(),
|
|
middlewareMatchers: expect.toBeArray(),
|
|
beforeFiles: expect.toBeArray(),
|
|
afterFiles: expect.toBeArray(),
|
|
dynamicRoutes: expect.toBeArray(),
|
|
onMatch: expect.toBeArray(),
|
|
fallback: expect.toBeArray(),
|
|
shouldNormalizeNextData: expect.toBeBoolean(),
|
|
rsc: expect.toBeObject(),
|
|
})
|
|
})
|
|
})
|