Unverified Commit 6c2e502a authored by Jamiboy Mohammad's avatar Jamiboy Mohammad Committed by GitHub

test: enable deploy coverage for routing build errors (#98848)

## Summary
Enable deployment coverage for 11 routing and validation exclusion
locations on top of #98776. Replace local-only build calls with explicit
start/failure assertions while preserving each expected diagnostic and
development behavior. The edge re-export test continues to accept a
successful Webpack build with warnings; Turbopack must fail.

## Verification
- Focused Turbopack production/development checks passed.
- Webpack production checks passed after correcting the edge re-export
expectation.
- Local checks used the published native binding. Exact native and
deploy validation are pending repository CI.

<!-- NEXT_JS_LLM -->
parent 4862c38b
......@@ -2,7 +2,7 @@ import { FileRef, nextTestSetup } from 'e2e-utils'
import path from 'path'
describe('app-dir edge SSR invalid reexport', () => {
const { next, isNextDev, skipped } = nextTestSetup({
const { next, isNextDev, isTurbopack } = nextTestSetup({
files: {
'app/layout.tsx': new FileRef(path.join(__dirname, 'app', 'layout.tsx')),
'app/export': new FileRef(path.join(__dirname, 'app', 'export')),
......@@ -10,18 +10,13 @@ describe('app-dir edge SSR invalid reexport', () => {
"export { default, runtime, preferredRegion } from '../basic/page'",
},
skipStart: true,
skipDeployment: true,
})
if (skipped) {
return
}
it('should warn or error about the re-export of a pages runtime/preferredRegion config', async () => {
try {
if (isNextDev || !isTurbopack) {
await next.start()
} catch (_) {
// We expect the build to fail
} else {
await expect(next.start()).rejects.toThrow()
}
if (isNextDev) {
......@@ -50,5 +45,5 @@ describe('app-dir edge SSR invalid reexport', () => {
expect(next.cliOutput).toInclude(
`Next.js can't recognize the exported \`preferredRegion\` field in`
)
})
}, 240_000)
})
......@@ -2,17 +2,13 @@ import { nextTestSetup } from 'e2e-utils'
import path from 'path'
describe('app-root-param-getters - generateStaticParams error', () => {
const { next, isNextDev, skipped } = nextTestSetup({
const { next, isNextDev } = nextTestSetup({
files: path.join(__dirname, 'fixtures', 'generate-static-params-error'),
skipStart: true,
skipDeployment: true,
})
if (skipped) return
beforeAll(async () => {
try {
await next.start()
} catch {}
if (isNextDev) await next.start()
})
if (isNextDev) {
......@@ -36,9 +32,10 @@ describe('app-root-param-getters - generateStaticParams error', () => {
})
} else {
it('should error when reading a root param inside the generateStaticParams that defines it - build', async () => {
await expect(next.start()).rejects.toThrow()
expect(next.cliOutput).toContain(
"Route /[lang]/[locale] used `import('next/root-params').lang()` inside `generateStaticParams`, but the `lang` parameter was not provided by a parent `generateStaticParams`. In `generateStaticParams`, root params are only available for segments nested below the segment that provides them."
)
})
}, 240_000)
}
})
......@@ -2,18 +2,11 @@ import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
describe('conflicting-page-segments', () => {
const { next, isNextDev, skipped } = nextTestSetup({
const { next, isNextDev } = nextTestSetup({
files: __dirname,
// we skip start & deploy because the build will fail and we won't be able to catch it
// start is re-triggered but caught in the assertions below.
skipStart: true,
skipDeployment: true,
})
if (skipped) {
return
}
it('should throw an error when a route groups causes a conflict with a parallel segment', async () => {
if (isNextDev) {
await next.start()
......@@ -23,7 +16,7 @@ describe('conflicting-page-segments', () => {
'You cannot have two parallel pages that resolve to the same path.'
)
} else {
await expect(next.start()).rejects.toThrow('next build failed')
await expect(next.start()).rejects.toThrow()
await retry(() => {
expect(next.cliOutput).toMatch(
......@@ -31,5 +24,5 @@ describe('conflicting-page-segments', () => {
)
})
}
})
}, 240_000)
})
......@@ -2,16 +2,11 @@ import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
describe('app dir - instant-validation-client', () => {
const { next, isNextDev, skipped } = nextTestSetup({
const { next, isNextDev } = nextTestSetup({
files: __dirname,
skipDeployment: true,
skipStart: true,
})
if (skipped) {
return
}
it('should error when a client component exports instant', async () => {
const expectedErrMsg = `"instant" is a route segment config and can only be used when the segment is a Server Component module. Remove the "use client" directive`
......@@ -22,8 +17,9 @@ describe('app dir - instant-validation-client', () => {
expect(next.cliOutput).toContain(expectedErrMsg)
})
} else {
const { cliOutput } = await next.build()
await expect(next.start()).rejects.toThrow()
const cliOutput = next.cliOutput
expect(cliOutput).toContain(expectedErrMsg)
}
})
}, 240_000)
})
import type { ChildProcess } from 'child_process'
import { isNextDev, isNextStart, nextTestSetup } from 'e2e-utils'
import { isNextDev, nextTestSetup } from 'e2e-utils'
import { findPort, killApp, retry } from 'next-test-utils'
describe('interception-routes-output-export', () => {
const { next } = nextTestSetup({
files: __dirname,
skipStart: true,
// Vercel deployment fails to build/deploy this fixture in CI; skip in deploy mode.
skipDeployment: true,
})
it('should error when using interception routes with static export', async () => {
if (isNextStart) {
const { exitCode, cliOutput } = await next.build()
if (!isNextDev) {
await expect(next.start()).rejects.toThrow()
const cliOutput = next.cliOutput
expect(cliOutput).toContain(
'Intercepting routes are not supported with static export.'
)
expect(exitCode).toBe(1)
} else if (isNextDev) {
let stderr = ''
let child: ChildProcess | undefined
......@@ -45,5 +43,5 @@ describe('interception-routes-output-export', () => {
await exit.catch(() => {})
}
}
})
}, 240_000)
})
......@@ -3,25 +3,21 @@ import { nextTestSetup } from 'e2e-utils'
import { waitForRedbox, retry } from 'next-test-utils'
describe('parallel-routes-leaf-segments-build-error', () => {
const { next, isNextDev, skipped } = nextTestSetup({
const { next, isNextDev } = nextTestSetup({
files: path.join(__dirname, 'fixtures', 'build-error'),
skipStart: true,
skipDeployment: true,
})
if (skipped) {
it.skip('skip test', () => {})
return
}
let buildError: unknown
if (isNextDev) {
beforeAll(() => next.start())
} else {
beforeAll(async () => {
try {
await next.build()
} catch {
// Expect build error
await next.start()
} catch (error) {
buildError = error
}
})
}
......@@ -45,6 +41,7 @@ describe('parallel-routes-leaf-segments-build-error', () => {
)
})
} else {
expect(buildError).toBeDefined()
await retry(() => {
expect(next.cliOutput).toContain('/with-children/@header/default.js')
})
......@@ -71,6 +68,7 @@ describe('parallel-routes-leaf-segments-build-error', () => {
)
})
} else {
expect(buildError).toBeDefined()
await retry(() => {
expect(next.cliOutput).toContain(
'/with-groups-and-children/(dashboard)/(overview)/@metrics/default.js'
......
......@@ -2,16 +2,11 @@ import { nextTestSetup } from 'e2e-utils'
import stripAnsi from 'strip-ansi'
describe('proxy-runtime', () => {
const { next, isNextDev, skipped } = nextTestSetup({
const { next, isNextDev, isNextDeploy } = nextTestSetup({
files: __dirname,
skipDeployment: true,
skipStart: true,
})
if (skipped) {
return
}
it('should error when proxy file has runtime config export', async () => {
let cliOutput: string
......@@ -21,12 +16,13 @@ describe('proxy-runtime', () => {
await next.browser('/').catch(() => {})
cliOutput = next.cliOutput
} else {
cliOutput = (await next.build()).cliOutput
await expect(next.start()).rejects.toThrow()
cliOutput = next.cliOutput
}
// TODO: Investigate why in dev-turbo, the error is shown in the browser console, not CLI output.
if (process.env.IS_TURBOPACK_TEST && !isNextDev) {
expect(stripAnsi(cliOutput)).toContain(`proxy.ts:3:14
const expected = `proxy.ts:3:14
Error: Next.js can't recognize the exported \`config\` field in route. Proxy does not support Edge runtime.
1 | export default function () {}
2 |
......@@ -34,13 +30,21 @@ Error: Next.js can't recognize the exported \`config\` field in route. Proxy doe
| ^^^^^^
4 |
The exported configuration object in a source file needs to have a very specific format from which some properties can be statically parsed at compiled-time.`)
The exported configuration object in a source file needs to have a very specific format from which some properties can be statically parsed at compiled-time.`
// Deployment logs add timestamps and remove code-frame indentation.
const normalize = (output: string) =>
isNextDeploy
? output
.replace(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z {2}/gm, '')
.replace(/^[ \t]+/gm, '')
: output
expect(normalize(stripAnsi(cliOutput))).toContain(normalize(expected))
} else {
expect(cliOutput).toContain(
`Route segment config is not allowed in Proxy file at "./proxy.ts". Proxy always runs on Node.js runtime. Learn more: https://nextjs.org/docs/messages/middleware-to-proxy`
)
}
await next.stop()
})
if (isNextDev) await next.stop()
}, 240_000)
})
......@@ -2,16 +2,11 @@ import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
describe('proxy-with-middleware', () => {
const { next, isNextDev, skipped } = nextTestSetup({
const { next, isNextDev } = nextTestSetup({
files: __dirname,
skipDeployment: true,
skipStart: true,
})
if (skipped) {
return
}
it('should error when both middleware and proxy files are detected', async () => {
const message =
'Both middleware file "./middleware.ts" and proxy file "./proxy.ts" are detected. Please use "./proxy.ts" only.'
......@@ -22,8 +17,9 @@ describe('proxy-with-middleware', () => {
expect(next.cliOutput).toContain(message)
})
} else {
const { cliOutput } = await next.build()
await expect(next.start()).rejects.toThrow()
const cliOutput = next.cliOutput
expect(cliOutput).toContain(message)
}
})
}, 240_000)
})
import path from 'path'
import { isNextStart, nextTestSetup } from 'e2e-utils'
import { isNextDev, nextTestSetup } from 'e2e-utils'
describe('Undefined default export', () => {
const { next, isNextDev } = nextTestSetup({
const { next } = nextTestSetup({
files: path.join(__dirname),
skipStart: isNextStart,
skipDeployment: true,
skipStart: !isNextDev,
})
if (isNextDev) {
......@@ -52,9 +51,8 @@ describe('Undefined default export', () => {
})
} else {
it('errors the build with helpful error messages', async () => {
const { cliOutput, exitCode } = await next.build()
expect(exitCode).toBe(1)
await expect(next.start()).rejects.toThrow()
const cliOutput = next.cliOutput
expect(cliOutput).toContain(
`Error occurred prerendering page "/specific-path/1". Read more: https://nextjs.org/docs/messages/prerender-error
......@@ -70,6 +68,6 @@ Error: The default export is not a React Component in "/specific-path/2/layout"`
`Error occurred prerendering page "/will-not-found". Read more: https://nextjs.org/docs/messages/prerender-error
Error: The default export is not a React Component in "/will-not-found/not-found"`
)
})
}, 240_000)
}
})
......@@ -7,8 +7,7 @@ import { nextTestSetup, isNextDev, isNextStart } from 'e2e-utils'
const { next } = nextTestSetup({
files: __dirname,
skipStart: isNextStart,
skipDeployment: true,
skipStart: !isNextDev,
})
if (isNextDev) {
......@@ -18,10 +17,11 @@ import { nextTestSetup, isNextDev, isNextStart } from 'e2e-utils'
})
}
if (isNextStart) {
if (!isNextDev) {
it('should catch it in server build mode', async () => {
const { cliOutput } = await next.build()
await expect(next.start()).rejects.toThrow()
const cliOutput = next.cliOutput
expect(cliOutput).toMatch(errorRegex)
})
}, 240_000)
}
})
import { nextTestSetup, isNextDev, isNextStart } from 'e2e-utils'
import { nextTestSetup, isNextDev } from 'e2e-utils'
describe('Errors on conflict between public file and page file', () => {
const { next, skipped } = nextTestSetup({
const { next } = nextTestSetup({
files: __dirname,
skipStart: true,
skipDeployment: true,
})
if (skipped) return
if (isNextDev) {
it('should show conflict error during development', async () => {
......@@ -24,9 +22,10 @@ describe('Errors on conflict between public file and page file', () => {
})
}
if (isNextStart) {
if (!isNextDev) {
it('should show conflict error during build', async () => {
const { cliOutput } = await next.build()
await expect(next.start()).rejects.toThrow()
const cliOutput = next.cliOutput
const conflicts = ['/another/conflict', '/another', '/hello']
expect(cliOutput).toMatch(/Conflicting public and page files were found/)
......@@ -34,6 +33,6 @@ describe('Errors on conflict between public file and page file', () => {
for (const conflict of conflicts) {
expect(cliOutput.indexOf(conflict) > 0).toBe(true)
}
})
}, 240_000)
}
})
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