Unverified Commit 3854a984 authored by Jamiboy Mohammad's avatar Jamiboy Mohammad Committed by GitHub

Enable deploy tests for reusable fixture variants (#99404)

## Summary

Enable deploy tests for the six remaining fixture-reuse files: the
conflict/group not-found routes, missing-Suspense and browser-bailout
variants, dynamic optional routing, and both middleware source-location
suites. Prepare each production variant before startup instead of
patching, renaming, cleaning, or rebuilding the same fixture.

Remove the file-level deployment skips while preserving every production
assertion and the existing dev file-mutation checks. Failed builds use
rejected startup with the same diagnostics; static-export tests check
the same warning after a local build or deployment. Forward the
browser-bailout flag explicitly to remote builds.

The middleware static-export fixtures explicitly disable Cache
Components and its dependent cached navigations flag, since static
export does not support PPR; both suites still execute their full build
and warning assertions in the Cache Components CI jobs.

## Verification

- Turbopack and Webpack production runs: 7 test entry points and 45
tests passed in each, including the browser-bailout wrapper.
- Turbopack and Webpack dev runs: 5 applicable entry points and 43 tests
passed in each; the two existing production-only skips are unchanged.
- TypeScript, ESLint, and Prettier passed.
- Additional Cache Components runs: both Suspense variants passed with
both bundlers. The two not-found files reproduce their existing
incompatibilities (Edge runtime; the conflict fixture also uses an
unguarded timestamp) and retain their existing Cache Components manifest
exclusions. No new skips are added.
- Reproduced all four middleware static-export failures with the Cache
Components CI feature flags. After the fixture fix, both suites pass all
four cases with Turbopack and Webpack under those flags.
- Standard deploy CI passed. Local deploy verification is blocked by the
Vercel project permissions; the corrected Cache Components deploy cases
await the new CI run.

<!-- NEXT_JS_LLM -->
parent 0abfbcbc
import { nextTestSetup } from 'e2e-utils'
import { FileRef, isNextDev, nextTestSetup } from 'e2e-utils'
import { join } from 'path'
describe('missing-suspense-with-csr-bailout', () => {
const { next, isNextDev, skipped } = nextTestSetup({
files: __dirname,
skipStart: true,
// This test is skipped when deployed because it's not possible to rename files after deployment.
skipDeployment: true,
})
if (skipped) {
return
}
if (isNextDev) {
it.skip('skip test for development mode', () => {})
return
}
beforeEach(async () => {
await next.clean()
})
const files = {
'next.config.js': new FileRef(join(__dirname, 'next.config.js')),
'app/layout.js': new FileRef(join(__dirname, 'app/layout.js')),
'app/dynamic': new FileRef(join(__dirname, 'app/dynamic')),
}
// The browser-bailout variant imports this suite with the flag enabled.
// Forward it explicitly so remote builds use the same configuration.
const env = {
TEST_REACT_BROWSER_BAILOUT: process.env.TEST_REACT_BROWSER_BAILOUT || '0',
}
const isCacheComponentsEnabled =
process.env.__NEXT_CACHE_COMPONENTS === 'true'
......@@ -29,41 +26,52 @@ describe('missing-suspense-with-csr-bailout', () => {
? 'https://nextjs.org/docs/messages/blocking-prerender-client-hook'
: `useSearchParams() should be wrapped in a suspense boundary at page "/".`
it('should fail build if useSearchParams is not wrapped in a suspense boundary', async () => {
const { exitCode } = await next.build()
expect(exitCode).toBe(1)
expect(next.cliOutput).toContain(message)
expect(next.cliOutput).not.toContain(
'The server render could not complete because client rendering was requested outside a Suspense boundary'
)
// Can show the trace where the searchParams hook is used
// TODO: This path is different for Turbopack. Builds need to have sourcemaps support.
if (!process.env.IS_TURBOPACK_TEST) {
expect(next.cliOutput).toMatch(/at.*server[\\/]app[\\/]page.js/)
}
})
describe('without Suspense', () => {
const { next } = nextTestSetup({
files: {
...files,
'app/page.js': new FileRef(join(__dirname, 'app/page.js')),
},
env,
skipStart: true,
})
it('should pass build if useSearchParams is wrapped in a suspense boundary', async () => {
await next.renameFile('app/layout.js', 'app/layout-no-suspense.js')
await next.renameFile('app/layout-suspense.js', 'app/layout.js')
it('should fail build if useSearchParams is not wrapped in a suspense boundary', async () => {
await expect(next.start()).rejects.toThrow()
expect(next.cliOutput).toContain(message)
expect(next.cliOutput).not.toContain(
'The server render could not complete because client rendering was requested outside a Suspense boundary'
)
// Can show the trace where the searchParams hook is used
// TODO: This path is different for Turbopack. Builds need to have sourcemaps support.
if (!process.env.IS_TURBOPACK_TEST) {
expect(next.cliOutput).toMatch(/at.*server[\\/]app[\\/]page.js/)
}
}, 240_000)
})
await expect(next.build()).resolves.toEqual({
exitCode: 0,
cliOutput: expect.not.stringContaining(message),
describe('with Suspense', () => {
const { next } = nextTestSetup({
files: {
...files,
'app/layout.js': new FileRef(
join(__dirname, 'app/layout-suspense.js')
),
'app/page.js': new FileRef(join(__dirname, 'app/page.js')),
},
env,
})
await next.renameFile('app/layout.js', 'app/layout-suspense.js')
await next.renameFile('app/layout-no-suspense.js', 'app/layout.js')
it('should pass build if useSearchParams is wrapped in a suspense boundary', () => {
expect(next.cliOutput).not.toContain(message)
})
})
})
describe('next/dynamic', () => {
beforeEach(async () => {
await next.renameFile('app/page.js', 'app/_page.js')
await next.start()
})
afterEach(async () => {
await next.renameFile('app/_page.js', 'app/page.js')
const { next } = nextTestSetup({
files,
env,
})
it('does not emit errors related to bailing out of client side rendering', async () => {
......
export const runtime = 'edge'
export default function Layout({ children }) {
return (
<html>
<head />
<body>
<header>
<nav id="layout-nav">Navbar</nav>
</header>
<main>{children}</main>
<footer>
<p id="layout-footer">Footer</p>
</footer>
</body>
</html>
)
}
import { nextTestSetup } from 'e2e-utils'
import { FileRef, nextTestSetup } from 'e2e-utils'
import { join } from 'path'
describe('app dir - not-found - conflict route', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
})
if (skipped) {
return
}
describe.each(['default', 'edge'])('with %s runtime', (runtime) => {
const { next } = nextTestSetup({
files: {
app: new FileRef(join(__dirname, 'app')),
...(runtime === 'edge' && {
'app/layout.js': new FileRef(join(__dirname, 'edge-layout.js')),
}),
},
})
const runTests = () => {
it('should use the not-found page for non-matching routes', async () => {
const browser = await next.browser('/random-content')
expect(await browser.elementByCss('h1').text()).toContain(
......@@ -24,28 +25,5 @@ describe('app dir - not-found - conflict route', () => {
const html = await next.render('/not-found')
expect(html).toContain('I am still a valid page')
})
}
describe('with default runtime', () => {
runTests()
})
describe('with runtime = edge', () => {
let originalLayout = ''
beforeAll(async () => {
await next.stop()
originalLayout = await next.readFile('app/layout.js')
await next.patchFile(
'app/layout.js',
`export const runtime = 'edge'\n${originalLayout}`
)
await next.start()
})
afterAll(async () => {
await next.patchFile('app/layout.js', originalLayout)
})
runTests()
})
})
export const runtime = 'edge'
export default function Layout({ children }) {
return (
<html>
<body>{children}</body>
</html>
)
}
import { nextTestSetup } from 'e2e-utils'
import { FileRef, nextTestSetup } from 'e2e-utils'
import { join } from 'path'
describe('app dir - not-found - group route', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
})
if (skipped) {
return
}
describe.each(['default', 'edge'])('with %s runtime', (runtime) => {
const { next } = nextTestSetup({
files: {
app: new FileRef(join(__dirname, 'app')),
...(runtime === 'edge' && {
'app/layout.js': new FileRef(join(__dirname, 'edge-layout.js')),
}),
},
})
const runTests = () => {
it('should use the not-found page under group routes', async () => {
const browser = await next.browser('/blog')
expect(await browser.elementByCss('h1').text()).toContain('Group Layout')
......@@ -18,28 +19,5 @@ describe('app dir - not-found - group route', () => {
'Not found!'
)
})
}
describe('with default runtime', () => {
runTests()
})
describe('with runtime = edge', () => {
let originalLayout = ''
beforeAll(async () => {
await next.stop()
originalLayout = await next.readFile('app/layout.js')
await next.patchFile(
'app/layout.js',
`export const runtime = 'edge'\n${originalLayout}`
)
await next.start()
})
afterAll(async () => {
await next.patchFile('app/layout.js', originalLayout)
})
runTests()
})
})
import cheerio from 'cheerio'
import { nextTestSetup, isNextDev } from 'e2e-utils'
import { FileRef, nextTestSetup, isNextDev } from 'e2e-utils'
import { join } from 'path'
import { retry } from 'next-test-utils'
const files = {
pages: new FileRef(join(__dirname, 'pages')),
'next.config.js': new FileRef(join(__dirname, 'next.config.js')),
}
describe('Dynamic Optional Routing', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
})
if (skipped) return
const { next } = nextTestSetup({ files })
it('should render catch-all top-level route with multiple segments', async () => {
const html = await next.render('/hello/world')
......@@ -217,82 +219,58 @@ describe('Dynamic Optional Routing', () => {
})
describe('Dynamic Optional Routing - build validation', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
skipStart: true,
skipDeployment: true,
})
if (skipped) return
const DUMMY_PAGE = 'export default () => null'
it('should fail to build when optional route has index.js at root', async () => {
await next.patchFile('pages/index.js', DUMMY_PAGE)
await next.build()
expect(next.cliOutput).toMatch(
/You cannot define a route with the same specificity as a optional catch-all route/
)
// Clean up for next test
await next.deleteFile('pages/index.js')
})
it('should fail to build when optional route has same page at root', async () => {
await next.patchFile('pages/nested.js', DUMMY_PAGE)
await next.build()
expect(next.cliOutput).toMatch(
/You cannot define a route with the same specificity as a optional catch-all route/
)
// Clean up for next test
await next.deleteFile('pages/nested.js')
})
it('should fail to build when mixed with regular catch-all', async () => {
await next.patchFile('pages/nested/[...param].js', DUMMY_PAGE)
await next.build()
expect(next.cliOutput).toMatch(/You cannot use both .+ at the same level/)
// Clean up for next test
await next.deleteFile('pages/nested/[...param].js')
})
it('should fail to build when optional but no catch-all', async () => {
await next.patchFile('pages/invalid/[[param]].js', DUMMY_PAGE)
await next.build()
expect(next.cliOutput).toMatch(
/Optional route parameters are not yet supported/
)
// Clean up for next test
await next.deleteFile('pages/invalid/[[param]].js')
})
it('should fail to build when param is not explicitly defined', async () => {
await next.patchFile(
'pages/invalid/[[...slug]].js',
`
export async function getStaticPaths() {
return {
paths: [
{ params: {} },
],
fallback: false,
}
}
export async function getStaticProps({ params }) {
return { props: { params } }
}
describe.each([
{
name: 'when optional route has index.js at root',
page: 'pages/index.js',
fixture: 'dummy-page.js',
message:
/You cannot define a route with the same specificity as a optional catch-all route/,
},
{
name: 'when optional route has same page at root',
page: 'pages/nested.js',
fixture: 'dummy-page.js',
message:
/You cannot define a route with the same specificity as a optional catch-all route/,
},
{
name: 'when mixed with regular catch-all',
page: 'pages/nested/[...param].js',
fixture: 'dummy-page.js',
message: /You cannot use both .+ at the same level/,
},
{
name: 'when optional but no catch-all',
page: 'pages/invalid/[[param]].js',
fixture: 'dummy-page.js',
message: /Optional route parameters are not yet supported/,
},
{
name: 'when param is not explicitly defined',
page: 'pages/invalid/[[...slug]].js',
fixture: 'missing-param.js',
message:
'A required parameter (slug) was not provided as an array received undefined in getStaticPaths for /invalid/[[...slug]]',
},
])('$name', ({ page, fixture, message }) => {
const { next } = nextTestSetup({
files: {
...files,
[page]: new FileRef(join(__dirname, 'fixtures', fixture)),
},
skipStart: true,
})
export default function Index(props) {
return (
<div>Invalid</div>
)
it('should fail to build', async () => {
if (isNextDev) {
// These build diagnostics also run in the dev test matrix.
const { exitCode } = await next.build()
expect(exitCode).toBe(1)
} else {
await expect(next.start()).rejects.toThrow()
}
`
)
await next.build()
expect(next.cliOutput).toMatch(
'A required parameter (slug) was not provided as an array received undefined in getStaticPaths for /invalid/[[...slug]]'
)
// Clean up
await next.deleteFile('pages/invalid/[[...slug]].js')
expect(next.cliOutput).toMatch(message)
}, 240_000)
})
})
export async function getStaticPaths() {
return { paths: [{ params: {} }], fallback: false }
}
export async function getStaticProps({ params }) {
return { props: { params } }
}
export default function Index() {
return <div>Invalid</div>
}
import { nextTestSetup, isNextDev } from 'e2e-utils'
import { FileRef, nextTestSetup, isNextDev } from 'e2e-utils'
import { join } from 'path'
import { retry } from 'next-test-utils'
const srcHeader = 'X-From-Src-Middleware'
const rootHeader = 'X-From-Root-Middleware'
describe('middleware-src-node', () => {
const { next, isTurbopack, skipped } = nextTestSetup({
files: __dirname,
skipStart: true,
skipDeployment: true,
})
if (skipped) return
if (isNextDev) {
beforeAll(async () => {
await next.start()
const { next, isTurbopack } = nextTestSetup({
files: __dirname,
})
}
describe('Middleware in src/ folder', () => {
if (isNextDev) {
describe('Middleware in src/ folder', () => {
it('loads and runs src middleware', async () => {
const response = await next.fetch('/post-1')
expect(response.headers.has(srcHeader)).toBe(false)
expect(response.headers.has(`${srcHeader}-TS`)).toBe(true)
})
}
})
if (!isNextDev) {
it('should warn about middleware on export', async () => {
describe('Middleware in src/ and / folders', () => {
beforeAll(async () => {
const pagesContent = await next.readFile('src/pages/index.js')
await next.patchFile('pages/index.js', pagesContent)
await next.patchFile(
'next.config.js',
"module.exports = { output: 'export' }"
'middleware.js',
await next.readFile('root/middleware.js')
)
await next.build()
expect(next.cliOutput).toContain(
'Statically exporting a Next.js application via `next export` disables API routes and middleware.'
await next.patchFile(
'middleware.ts',
await next.readFile('root/middleware.ts')
)
// Webpack needs a restart to resolve newly added root middleware.
// Turbopack picks up the change while the dev server is running.
if (!isTurbopack) {
await next.stop()
await next.start()
}
})
}
})
describe('Middleware in src/ and / folders', () => {
beforeAll(async () => {
const pagesContent = await next.readFile('src/pages/index.js')
await next.patchFile('pages/index.js', pagesContent)
await next.patchFile(
'middleware.js',
`
import { NextResponse } from 'next/server'
export default function () {
const response = NextResponse.next()
response.headers.set('${rootHeader}', 'true')
return response
}`
)
await next.patchFile(
'middleware.ts',
`
import { NextResponse } from 'next/server'
export default function () {
const response = NextResponse.next()
response.headers.set('${rootHeader}-TS', 'true')
return response
}`
)
// Webpack dev does not reliably switch from the already-compiled
// src/middleware.* to the newly created root middleware.* files when
// they are added at runtime. Restarting the dev server forces a fresh
// middleware resolution. Turbopack picks up the new root middleware
// without a restart. In production mode no server is running here
// (skipStart: true), so the restart must not run.
if (isNextDev && !isTurbopack) {
await next.stop()
await next.start()
}
})
afterAll(async () => {
await next.deleteFile('pages/index.js').catch(() => {})
await next.deleteFile('middleware.js').catch(() => {})
await next.deleteFile('middleware.ts').catch(() => {})
})
afterAll(async () => {
await next.deleteFile('pages/index.js').catch(() => {})
await next.deleteFile('middleware.js').catch(() => {})
await next.deleteFile('middleware.ts').catch(() => {})
})
if (isNextDev) {
it('loads and runs only root middleware', async () => {
await retry(async () => {
const response = await next.fetch('/post-1')
......@@ -95,19 +54,45 @@ export default function () {
expect(response.headers.has(`${rootHeader}-TS`)).toBe(true)
})
})
}
})
} else {
describe.each([
['src/ folder', false],
['src/ and / folders', true],
])('Middleware in %s', (_name, withRootMiddleware) => {
const { next, isNextDeploy } = nextTestSetup({
files: {
src: new FileRef(join(__dirname, 'src')),
...(withRootMiddleware && {
'pages/index.js': new FileRef(
join(__dirname, 'src/pages/index.js')
),
'middleware.js': new FileRef(join(__dirname, 'root/middleware.js')),
'middleware.ts': new FileRef(join(__dirname, 'root/middleware.ts')),
}),
},
nextConfig: {
output: 'export',
// Static export does not support Cache Components. Disable the
// dependent cached navigations flag too, since CI enables both.
cacheComponents: false,
experimental: { cachedNavigations: false },
},
skipStart: true,
})
if (!isNextDev) {
it('should warn about middleware on export', async () => {
await next.patchFile(
'next.config.js',
"module.exports = { output: 'export' }"
)
await next.build()
if (isNextDeploy) {
await next.start()
} else {
// A static export builds successfully but cannot use `next start`.
const { exitCode } = await next.build()
expect(exitCode).toBe(0)
}
expect(next.cliOutput).toContain(
'Statically exporting a Next.js application via `next export` disables API routes and middleware.'
)
})
}
})
}, 240_000)
})
}
})
import { NextResponse } from 'next/server'
export default function () {
const response = NextResponse.next()
response.headers.set('X-From-Root-Middleware', 'true')
return response
}
import { NextResponse } from 'next/server'
export default function () {
const response = NextResponse.next()
response.headers.set('X-From-Root-Middleware-TS', 'true')
return response
}
import { nextTestSetup, isNextDev } from 'e2e-utils'
import { FileRef, nextTestSetup, isNextDev } from 'e2e-utils'
import { join } from 'path'
import { retry } from 'next-test-utils'
const srcHeader = 'X-From-Src-Middleware'
const rootHeader = 'X-From-Root-Middleware'
describe('middleware-src', () => {
const { next, isTurbopack, skipped } = nextTestSetup({
files: __dirname,
skipStart: true,
skipDeployment: true,
})
if (skipped) return
if (isNextDev) {
beforeAll(async () => {
await next.start()
const { next, isTurbopack } = nextTestSetup({
files: __dirname,
})
}
describe('Middleware in src/ folder', () => {
if (isNextDev) {
describe('Middleware in src/ folder', () => {
it('loads and runs src middleware', async () => {
const response = await next.fetch('/post-1')
expect(response.headers.has(srcHeader)).toBe(false)
expect(response.headers.has(`${srcHeader}-TS`)).toBe(true)
})
}
})
if (!isNextDev) {
it('should warn about middleware on export', async () => {
describe('Middleware in src/ and / folders', () => {
beforeAll(async () => {
const pagesContent = await next.readFile('src/pages/index.js')
await next.patchFile('pages/index.js', pagesContent)
await next.patchFile(
'next.config.js',
"module.exports = { output: 'export' }"
'middleware.js',
await next.readFile('root/middleware.js')
)
await next.build()
expect(next.cliOutput).toContain(
'Statically exporting a Next.js application via `next export` disables API routes and middleware.'
await next.patchFile(
'middleware.ts',
await next.readFile('root/middleware.ts')
)
// Webpack needs a restart to resolve newly added root middleware.
// Turbopack picks up the change while the dev server is running.
if (!isTurbopack) {
await next.stop()
await next.start()
}
})
}
})
describe('Middleware in src/ and / folders', () => {
beforeAll(async () => {
const pagesContent = await next.readFile('src/pages/index.js')
await next.patchFile('pages/index.js', pagesContent)
await next.patchFile(
'middleware.js',
`
import { NextResponse } from 'next/server'
export default function () {
const response = NextResponse.next()
response.headers.set('${rootHeader}', 'true')
return response
}`
)
await next.patchFile(
'middleware.ts',
`
import { NextResponse } from 'next/server'
export default function () {
const response = NextResponse.next()
response.headers.set('${rootHeader}-TS', 'true')
return response
}`
)
// Webpack dev does not reliably switch from the already-compiled
// src/middleware.* to the newly created root middleware.* files when
// they are added at runtime. Restarting the dev server forces a fresh
// middleware resolution. Turbopack picks up the new root middleware
// without a restart. In production mode the server is never started
// (skipStart: true + only `next.build()` is invoked), so the restart
// dance must be limited to dev mode.
if (isNextDev && !isTurbopack) {
await next.stop()
await next.start()
}
})
afterAll(async () => {
await next.deleteFile('pages/index.js').catch(() => {})
await next.deleteFile('middleware.js').catch(() => {})
await next.deleteFile('middleware.ts').catch(() => {})
})
afterAll(async () => {
await next.deleteFile('pages/index.js').catch(() => {})
await next.deleteFile('middleware.js').catch(() => {})
await next.deleteFile('middleware.ts').catch(() => {})
})
if (isNextDev) {
it('loads and runs only root middleware', async () => {
await retry(async () => {
const response = await next.fetch('/post-1')
......@@ -96,19 +54,45 @@ export default function () {
expect(response.headers.has(`${rootHeader}-TS`)).toBe(true)
})
})
}
})
} else {
describe.each([
['src/ folder', false],
['src/ and / folders', true],
])('Middleware in %s', (_name, withRootMiddleware) => {
const { next, isNextDeploy } = nextTestSetup({
files: {
src: new FileRef(join(__dirname, 'src')),
...(withRootMiddleware && {
'pages/index.js': new FileRef(
join(__dirname, 'src/pages/index.js')
),
'middleware.js': new FileRef(join(__dirname, 'root/middleware.js')),
'middleware.ts': new FileRef(join(__dirname, 'root/middleware.ts')),
}),
},
nextConfig: {
output: 'export',
// Static export does not support Cache Components. Disable the
// dependent cached navigations flag too, since CI enables both.
cacheComponents: false,
experimental: { cachedNavigations: false },
},
skipStart: true,
})
if (!isNextDev) {
it('should warn about middleware on export', async () => {
await next.patchFile(
'next.config.js',
"module.exports = { output: 'export' }"
)
await next.build()
if (isNextDeploy) {
await next.start()
} else {
// A static export builds successfully but cannot use `next start`.
const { exitCode } = await next.build()
expect(exitCode).toBe(0)
}
expect(next.cliOutput).toContain(
'Statically exporting a Next.js application via `next export` disables API routes and middleware.'
)
})
}
})
}, 240_000)
})
}
})
import { NextResponse } from 'next/server'
export default function () {
const response = NextResponse.next()
response.headers.set('X-From-Root-Middleware', 'true')
return response
}
import { NextResponse } from 'next/server'
export default function () {
const response = NextResponse.next()
response.headers.set('X-From-Root-Middleware-TS', 'true')
return response
}
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