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

Add segment config parity regression tests

Co-authored-by: 's avatarNiklas Mischkulnig <4586894+mischnic@users.noreply.github.com>
parent 4bfbf238
import type { ReactNode } from 'react'
export const runtime = 'edge'
export default function Root({ children }: { children: ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
import { readFileSync } from 'node:fs'
export const runtime = 'nodejs'
export default function NotFound() {
return (
<>
<p id="runtime">{process.env.NEXT_RUNTIME}</p>
<p id="node-api">{typeof readFileSync}</p>
</>
)
}
export const runtime = 'nodejs'
export default function Page() {
return <p id="runtime">{process.env.NEXT_RUNTIME}</p>
}
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {}
export default nextConfig
import { load } from 'cheerio'
import { nextTestSetup } from 'e2e-utils'
describe('segment-config-not-found-runtime', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('serves a Node-only custom 404 under an Edge root layout', async () => {
const page = await next.render$('/')
expect(page('#runtime').text()).toBe('nodejs')
const response = await next.fetch('/missing')
expect(response.status).toBe(404)
const $ = load(await response.text())
expect($('#runtime').text()).toBe('nodejs')
expect($('#node-api').text()).toBe('function')
})
})
export default function Layout({ children }) {
return (
<html>
<body>{children}</body>
</html>
)
}
export const runtime = 'nodejs'
export default function Page() {
return <p id="runtime">{process.env.NEXT_RUNTIME}</p>
}
export default function Layout({ children, slot }) {
return (
<>
{children}
{slot}
</>
)
}
export const maxDuration = 4294967296
export default function Page() {
return <p id="children">children</p>
}
export const maxDuration = 4294967295
export default function Page() {
return <p id="children">children</p>
}
export const dynamic = 'force-static'
export default function Layout({ children }) {
return children
}
export default function Page() {
return <p id="slot">slot</p>
}
import { randomUUID } from 'node:crypto'
export const dynamic = 'force-dynamic'
export default function Page() {
return (
<>
<p id="children">children</p>
<p id="render">{randomUUID()}</p>
</>
)
}
export const dynamicParams = true
export default function Page() {
return <p id="slot">slot</p>
}
export const dynamicParams = false
export function generateStaticParams() {
return [{ id: 'known' }]
}
export default async function Page({ params }) {
const { id } = await params
return <p id="children">{id}</p>
}
export const dynamic = 'auto'
export default function Page() {
return <p id="slot">slot</p>
}
import { randomUUID } from 'node:crypto'
export const dynamic = 'force-dynamic'
export default function Page() {
return (
<>
<p id="children">children</p>
<p id="render">{randomUUID()}</p>
</>
)
}
export const runtime = 'edge'
export default function Page() {
return (
<>
<p id="which">slot</p>
<p id="runtime">{process.env.NEXT_RUNTIME}</p>
</>
)
}
export const runtime = 'edge'
export default function Page() {
return (
<>
<p id="which">main</p>
<p id="runtime">{process.env.NEXT_RUNTIME}</p>
</>
)
}
export const fetchCache = 'auto'
export default function Page() {
return <p id="slot">slot</p>
}
export const fetchCache = 'force-no-store'
export default function Page() {
return <p id="children">children</p>
}
export const runtime = 'edge'
export const preferredRegion = 'sfo1'
export default function GlobalNotFound() {
return (
<html>
<body>
<p id="runtime">{process.env.NEXT_RUNTIME}</p>
</body>
</html>
)
}
module.exports = {
experimental: {
globalNotFound: true,
},
}
export const runtime = 'nodejs'
export default function Layout({ children }) {
return (
<>
<p id="layout">js</p>
{children}
</>
)
}
export const runtime = 'edge'
export default function Layout({ children }) {
return (
<>
<p id="layout">jsx</p>
{children}
</>
)
}
export default function Page() {
return <p id="runtime">{process.env.NEXT_RUNTIME}</p>
}
export const runtime = 'edge'
export default function Layout({ children }) {
return (
<html>
<body>{children}</body>
</html>
)
}
import { readFileSync } from 'node:fs'
export const runtime = 'nodejs'
export default function NotFound() {
return (
<>
<p id="runtime">{process.env.NEXT_RUNTIME}</p>
<p id="node-api">{typeof readFileSync}</p>
</>
)
}
export const revalidate = 120
export default function Page() {
return <p id="slot">slot</p>
}
export const revalidate = 60
export default function Page() {
return <p id="children">children</p>
}
import { load } from 'cheerio'
import { FileRef, nextTestSetup, type NextInstance } from 'e2e-utils'
import path from 'path'
const fixtures = path.join(__dirname, 'fixtures')
function commonFiles() {
return {
app: new FileRef(path.join(fixtures, 'common', 'app')),
}
}
function routeFiles(name: string, parallel = false) {
return {
...commonFiles(),
...(parallel
? {
'app/check/layout.jsx': new FileRef(
path.join(fixtures, 'common', 'slot-layout.jsx')
),
}
: {}),
'app/check': new FileRef(path.join(fixtures, name)),
}
}
async function buildAndStart(next: NextInstance) {
const { exitCode, cliOutput } = await next.build()
// Include the build diagnostic when a bundler rejects a webpack-valid fixture.
expect({ exitCode, cliOutput }).toEqual({
exitCode: 0,
cliOutput: expect.any(String),
})
await next.start({ skipBuild: true })
}
async function expectNodeNotFound(next: NextInstance) {
const response = await next.fetch('/missing')
expect(response.status).toBe(404)
const $ = load(await response.text())
expect($('#runtime').text()).toBe('nodejs')
const middleware = await next.readJSON(
'.next/server/middleware-manifest.json'
)
expect(middleware.functions['/_not-found/page']).toBeUndefined()
return $
}
describe('segment-config-parity', () => {
describe('synthetic not-found', () => {
const { next } = nextTestSetup({
files: {
...commonFiles(),
'app/layout.jsx': new FileRef(
path.join(fixtures, 'not-found', 'layout.jsx')
),
'app/not-found.jsx': new FileRef(
path.join(fixtures, 'not-found', 'not-found.jsx')
),
},
skipStart: true,
})
it('supports a Node-only custom 404 under an Edge root layout', async () => {
await buildAndStart(next)
const page = await next.render$('/')
expect(page('#runtime').text()).toBe('nodejs')
const $ = await expectNodeNotFound(next)
expect($('#node-api').text()).toBe('function')
})
})
describe.each(['dynamic', 'dynamic-layout', 'revalidate', 'fetch-cache'])(
'unequal sibling rendering config: %s',
(fixture) => {
const { next } = nextTestSetup({
files: routeFiles(fixture, true),
skipStart: true,
})
it('builds and renders both branches with their rendering configs', async () => {
await buildAndStart(next)
const $ = await next.render$('/check')
expect($('#children').text()).toBe('children')
expect($('#slot').text()).toBe('slot')
if (fixture === 'dynamic' || fixture === 'dynamic-layout') {
const second = await next.render$('/check')
expect($('#render').text()).not.toBe('')
expect(second('#render').text()).not.toBe($('#render').text())
const prerender = await next.readJSON('.next/prerender-manifest.json')
expect(prerender.routes['/check']).toBeUndefined()
} else if (fixture === 'revalidate') {
const prerender = await next.readJSON('.next/prerender-manifest.json')
expect(prerender.routes['/check'].initialRevalidateSeconds).toBe(60)
}
})
}
)
describe('unequal sibling dynamicParams', () => {
const { next } = nextTestSetup({
files: routeFiles('dynamic-params', true),
skipStart: true,
})
it('renders the generated parameter and rejects an ungenerated one', async () => {
await buildAndStart(next)
const $ = await next.render$('/check/known')
expect($('#children').text()).toBe('known')
expect($('#slot').text()).toBe('slot')
expect((await next.fetch('/check/unknown')).status).toBe(404)
})
})
describe('global-not-found deployment exports', () => {
const { next } = nextTestSetup({
files: {
...commonFiles(),
'app/global-not-found.jsx': new FileRef(
path.join(fixtures, 'global-not-found', 'global-not-found.jsx')
),
'next.config.js': new FileRef(
path.join(fixtures, 'global-not-found', 'next.config.js')
),
},
skipStart: true,
})
it('does not turn a global 404 into an Edge function with regions', async () => {
await buildAndStart(next)
await expectNodeNotFound(next)
})
})
describe('explicit children slot', () => {
const { next } = nextTestSetup({
files: routeFiles('explicit-children'),
skipStart: true,
})
it('accepts an ordinary page alongside an explicit @children page', async () => {
await buildAndStart(next)
const response = await next.fetch('/check')
expect(response.status).toBe(200)
const $ = load(await response.text())
expect($('#which').text()).toBe('main')
expect($('#runtime').text()).toBe('edge')
const middleware = await next.readJSON(
'.next/server/middleware-manifest.json'
)
expect(middleware.functions['/check/page']).toBeDefined()
expect(middleware.functions['/check/@children/page']).toBeDefined()
})
})
describe.each([
{ fixture: 'duration-u32', duration: 4294967295 },
{ fixture: 'duration-above-u32', duration: 4294967296 },
])('maxDuration: $duration', ({ fixture, duration }) => {
const { next } = nextTestSetup({
files: routeFiles(fixture),
skipStart: true,
})
it('accepts the non-negative integer and preserves its manifest value', async () => {
await buildAndStart(next)
const $ = await next.render$('/check')
expect($('#children').text()).toBe('children')
const functionsConfig = await next.readJSON(
'.next/server/functions-config-manifest.json'
)
expect(functionsConfig.functions['/check']).toEqual({
maxDuration: duration,
})
})
})
describe('duplicate layout extensions', () => {
const { next } = nextTestSetup({
files: {
...routeFiles('layout-extensions'),
'next.config.js': new FileRef(
path.join(fixtures, 'layout-extensions.config.js')
),
},
skipStart: true,
})
it('uses the first page extension for both the layout and its runtime', async () => {
await buildAndStart(next)
const $ = await next.render$('/check')
expect($('#layout').text()).toBe('jsx')
expect($('#runtime').text()).toBe('edge')
const middleware = await next.readJSON(
'.next/server/middleware-manifest.json'
)
expect(middleware.functions['/check/page']).toBeDefined()
})
})
})
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