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' ...@@ -2,7 +2,7 @@ import { FileRef, nextTestSetup } from 'e2e-utils'
import path from 'path' import path from 'path'
describe('app-dir edge SSR invalid reexport', () => { describe('app-dir edge SSR invalid reexport', () => {
const { next, isNextDev, skipped } = nextTestSetup({ const { next, isNextDev, isTurbopack } = nextTestSetup({
files: { files: {
'app/layout.tsx': new FileRef(path.join(__dirname, 'app', 'layout.tsx')), 'app/layout.tsx': new FileRef(path.join(__dirname, 'app', 'layout.tsx')),
'app/export': new FileRef(path.join(__dirname, 'app', 'export')), 'app/export': new FileRef(path.join(__dirname, 'app', 'export')),
...@@ -10,18 +10,13 @@ describe('app-dir edge SSR invalid reexport', () => { ...@@ -10,18 +10,13 @@ describe('app-dir edge SSR invalid reexport', () => {
"export { default, runtime, preferredRegion } from '../basic/page'", "export { default, runtime, preferredRegion } from '../basic/page'",
}, },
skipStart: true, skipStart: true,
skipDeployment: true,
}) })
if (skipped) {
return
}
it('should warn or error about the re-export of a pages runtime/preferredRegion config', async () => { it('should warn or error about the re-export of a pages runtime/preferredRegion config', async () => {
try { if (isNextDev || !isTurbopack) {
await next.start() await next.start()
} catch (_) { } else {
// We expect the build to fail await expect(next.start()).rejects.toThrow()
} }
if (isNextDev) { if (isNextDev) {
...@@ -50,5 +45,5 @@ describe('app-dir edge SSR invalid reexport', () => { ...@@ -50,5 +45,5 @@ describe('app-dir edge SSR invalid reexport', () => {
expect(next.cliOutput).toInclude( expect(next.cliOutput).toInclude(
`Next.js can't recognize the exported \`preferredRegion\` field in` `Next.js can't recognize the exported \`preferredRegion\` field in`
) )
}) }, 240_000)
}) })
...@@ -2,17 +2,13 @@ import { nextTestSetup } from 'e2e-utils' ...@@ -2,17 +2,13 @@ import { nextTestSetup } from 'e2e-utils'
import path from 'path' import path from 'path'
describe('app-root-param-getters - generateStaticParams error', () => { 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'), files: path.join(__dirname, 'fixtures', 'generate-static-params-error'),
skipStart: true, skipStart: true,
skipDeployment: true,
}) })
if (skipped) return
beforeAll(async () => { beforeAll(async () => {
try { if (isNextDev) await next.start()
await next.start()
} catch {}
}) })
if (isNextDev) { if (isNextDev) {
...@@ -36,9 +32,10 @@ describe('app-root-param-getters - generateStaticParams error', () => { ...@@ -36,9 +32,10 @@ describe('app-root-param-getters - generateStaticParams error', () => {
}) })
} else { } else {
it('should error when reading a root param inside the generateStaticParams that defines it - build', async () => { 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( 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." "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' ...@@ -2,18 +2,11 @@ import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils' import { retry } from 'next-test-utils'
describe('conflicting-page-segments', () => { describe('conflicting-page-segments', () => {
const { next, isNextDev, skipped } = nextTestSetup({ const { next, isNextDev } = nextTestSetup({
files: __dirname, 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, skipStart: true,
skipDeployment: true,
}) })
if (skipped) {
return
}
it('should throw an error when a route groups causes a conflict with a parallel segment', async () => { it('should throw an error when a route groups causes a conflict with a parallel segment', async () => {
if (isNextDev) { if (isNextDev) {
await next.start() await next.start()
...@@ -23,7 +16,7 @@ describe('conflicting-page-segments', () => { ...@@ -23,7 +16,7 @@ describe('conflicting-page-segments', () => {
'You cannot have two parallel pages that resolve to the same path.' 'You cannot have two parallel pages that resolve to the same path.'
) )
} else { } else {
await expect(next.start()).rejects.toThrow('next build failed') await expect(next.start()).rejects.toThrow()
await retry(() => { await retry(() => {
expect(next.cliOutput).toMatch( expect(next.cliOutput).toMatch(
...@@ -31,5 +24,5 @@ describe('conflicting-page-segments', () => { ...@@ -31,5 +24,5 @@ describe('conflicting-page-segments', () => {
) )
}) })
} }
}) }, 240_000)
}) })
...@@ -2,16 +2,11 @@ import { nextTestSetup } from 'e2e-utils' ...@@ -2,16 +2,11 @@ import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils' import { retry } from 'next-test-utils'
describe('app dir - instant-validation-client', () => { describe('app dir - instant-validation-client', () => {
const { next, isNextDev, skipped } = nextTestSetup({ const { next, isNextDev } = nextTestSetup({
files: __dirname, files: __dirname,
skipDeployment: true,
skipStart: true, skipStart: true,
}) })
if (skipped) {
return
}
it('should error when a client component exports instant', async () => { 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` 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', () => { ...@@ -22,8 +17,9 @@ describe('app dir - instant-validation-client', () => {
expect(next.cliOutput).toContain(expectedErrMsg) expect(next.cliOutput).toContain(expectedErrMsg)
}) })
} else { } else {
const { cliOutput } = await next.build() await expect(next.start()).rejects.toThrow()
const cliOutput = next.cliOutput
expect(cliOutput).toContain(expectedErrMsg) expect(cliOutput).toContain(expectedErrMsg)
} }
}) }, 240_000)
}) })
import type { ChildProcess } from 'child_process' 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' import { findPort, killApp, retry } from 'next-test-utils'
describe('interception-routes-output-export', () => { describe('interception-routes-output-export', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
skipStart: true, 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 () => { it('should error when using interception routes with static export', async () => {
if (isNextStart) { if (!isNextDev) {
const { exitCode, cliOutput } = await next.build() await expect(next.start()).rejects.toThrow()
const cliOutput = next.cliOutput
expect(cliOutput).toContain( expect(cliOutput).toContain(
'Intercepting routes are not supported with static export.' 'Intercepting routes are not supported with static export.'
) )
expect(exitCode).toBe(1)
} else if (isNextDev) { } else if (isNextDev) {
let stderr = '' let stderr = ''
let child: ChildProcess | undefined let child: ChildProcess | undefined
...@@ -45,5 +43,5 @@ describe('interception-routes-output-export', () => { ...@@ -45,5 +43,5 @@ describe('interception-routes-output-export', () => {
await exit.catch(() => {}) await exit.catch(() => {})
} }
} }
}) }, 240_000)
}) })
...@@ -3,25 +3,21 @@ import { nextTestSetup } from 'e2e-utils' ...@@ -3,25 +3,21 @@ import { nextTestSetup } from 'e2e-utils'
import { waitForRedbox, retry } from 'next-test-utils' import { waitForRedbox, retry } from 'next-test-utils'
describe('parallel-routes-leaf-segments-build-error', () => { describe('parallel-routes-leaf-segments-build-error', () => {
const { next, isNextDev, skipped } = nextTestSetup({ const { next, isNextDev } = nextTestSetup({
files: path.join(__dirname, 'fixtures', 'build-error'), files: path.join(__dirname, 'fixtures', 'build-error'),
skipStart: true, skipStart: true,
skipDeployment: true,
}) })
if (skipped) { let buildError: unknown
it.skip('skip test', () => {})
return
}
if (isNextDev) { if (isNextDev) {
beforeAll(() => next.start()) beforeAll(() => next.start())
} else { } else {
beforeAll(async () => { beforeAll(async () => {
try { try {
await next.build() await next.start()
} catch { } catch (error) {
// Expect build error buildError = error
} }
}) })
} }
...@@ -45,6 +41,7 @@ describe('parallel-routes-leaf-segments-build-error', () => { ...@@ -45,6 +41,7 @@ describe('parallel-routes-leaf-segments-build-error', () => {
) )
}) })
} else { } else {
expect(buildError).toBeDefined()
await retry(() => { await retry(() => {
expect(next.cliOutput).toContain('/with-children/@header/default.js') expect(next.cliOutput).toContain('/with-children/@header/default.js')
}) })
...@@ -71,6 +68,7 @@ describe('parallel-routes-leaf-segments-build-error', () => { ...@@ -71,6 +68,7 @@ describe('parallel-routes-leaf-segments-build-error', () => {
) )
}) })
} else { } else {
expect(buildError).toBeDefined()
await retry(() => { await retry(() => {
expect(next.cliOutput).toContain( expect(next.cliOutput).toContain(
'/with-groups-and-children/(dashboard)/(overview)/@metrics/default.js' '/with-groups-and-children/(dashboard)/(overview)/@metrics/default.js'
......
...@@ -2,16 +2,11 @@ import { nextTestSetup } from 'e2e-utils' ...@@ -2,16 +2,11 @@ import { nextTestSetup } from 'e2e-utils'
import stripAnsi from 'strip-ansi' import stripAnsi from 'strip-ansi'
describe('proxy-runtime', () => { describe('proxy-runtime', () => {
const { next, isNextDev, skipped } = nextTestSetup({ const { next, isNextDev, isNextDeploy } = nextTestSetup({
files: __dirname, files: __dirname,
skipDeployment: true,
skipStart: true, skipStart: true,
}) })
if (skipped) {
return
}
it('should error when proxy file has runtime config export', async () => { it('should error when proxy file has runtime config export', async () => {
let cliOutput: string let cliOutput: string
...@@ -21,12 +16,13 @@ describe('proxy-runtime', () => { ...@@ -21,12 +16,13 @@ describe('proxy-runtime', () => {
await next.browser('/').catch(() => {}) await next.browser('/').catch(() => {})
cliOutput = next.cliOutput cliOutput = next.cliOutput
} else { } 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. // TODO: Investigate why in dev-turbo, the error is shown in the browser console, not CLI output.
if (process.env.IS_TURBOPACK_TEST && !isNextDev) { 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. Error: Next.js can't recognize the exported \`config\` field in route. Proxy does not support Edge runtime.
1 | export default function () {} 1 | export default function () {}
2 | 2 |
...@@ -34,13 +30,21 @@ Error: Next.js can't recognize the exported \`config\` field in route. Proxy doe ...@@ -34,13 +30,21 @@ Error: Next.js can't recognize the exported \`config\` field in route. Proxy doe
| ^^^^^^ | ^^^^^^
4 | 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 { } else {
expect(cliOutput).toContain( 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` `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' ...@@ -2,16 +2,11 @@ import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils' import { retry } from 'next-test-utils'
describe('proxy-with-middleware', () => { describe('proxy-with-middleware', () => {
const { next, isNextDev, skipped } = nextTestSetup({ const { next, isNextDev } = nextTestSetup({
files: __dirname, files: __dirname,
skipDeployment: true,
skipStart: true, skipStart: true,
}) })
if (skipped) {
return
}
it('should error when both middleware and proxy files are detected', async () => { it('should error when both middleware and proxy files are detected', async () => {
const message = const message =
'Both middleware file "./middleware.ts" and proxy file "./proxy.ts" are detected. Please use "./proxy.ts" only.' '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', () => { ...@@ -22,8 +17,9 @@ describe('proxy-with-middleware', () => {
expect(next.cliOutput).toContain(message) expect(next.cliOutput).toContain(message)
}) })
} else { } else {
const { cliOutput } = await next.build() await expect(next.start()).rejects.toThrow()
const cliOutput = next.cliOutput
expect(cliOutput).toContain(message) expect(cliOutput).toContain(message)
} }
}) }, 240_000)
}) })
import path from 'path' import path from 'path'
import { isNextStart, nextTestSetup } from 'e2e-utils' import { isNextDev, nextTestSetup } from 'e2e-utils'
describe('Undefined default export', () => { describe('Undefined default export', () => {
const { next, isNextDev } = nextTestSetup({ const { next } = nextTestSetup({
files: path.join(__dirname), files: path.join(__dirname),
skipStart: isNextStart, skipStart: !isNextDev,
skipDeployment: true,
}) })
if (isNextDev) { if (isNextDev) {
...@@ -52,9 +51,8 @@ describe('Undefined default export', () => { ...@@ -52,9 +51,8 @@ describe('Undefined default export', () => {
}) })
} else { } else {
it('errors the build with helpful error messages', async () => { it('errors the build with helpful error messages', async () => {
const { cliOutput, exitCode } = await next.build() await expect(next.start()).rejects.toThrow()
const cliOutput = next.cliOutput
expect(exitCode).toBe(1)
expect(cliOutput).toContain( expect(cliOutput).toContain(
`Error occurred prerendering page "/specific-path/1". Read more: https://nextjs.org/docs/messages/prerender-error `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"` ...@@ -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 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"` 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' ...@@ -7,8 +7,7 @@ import { nextTestSetup, isNextDev, isNextStart } from 'e2e-utils'
const { next } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
skipStart: isNextStart, skipStart: !isNextDev,
skipDeployment: true,
}) })
if (isNextDev) { if (isNextDev) {
...@@ -18,10 +17,11 @@ import { nextTestSetup, isNextDev, isNextStart } from 'e2e-utils' ...@@ -18,10 +17,11 @@ import { nextTestSetup, isNextDev, isNextStart } from 'e2e-utils'
}) })
} }
if (isNextStart) { if (!isNextDev) {
it('should catch it in server build mode', async () => { 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) 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', () => { describe('Errors on conflict between public file and page file', () => {
const { next, skipped } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
skipStart: true, skipStart: true,
skipDeployment: true,
}) })
if (skipped) return
if (isNextDev) { if (isNextDev) {
it('should show conflict error during development', async () => { it('should show conflict error during development', async () => {
...@@ -24,9 +22,10 @@ describe('Errors on conflict between public file and page file', () => { ...@@ -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 () => { 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'] const conflicts = ['/another/conflict', '/another', '/hello']
expect(cliOutput).toMatch(/Conflicting public and page files were found/) expect(cliOutput).toMatch(/Conflicting public and page files were found/)
...@@ -34,6 +33,6 @@ describe('Errors on conflict between public file and page file', () => { ...@@ -34,6 +33,6 @@ describe('Errors on conflict between public file and page file', () => {
for (const conflict of conflicts) { for (const conflict of conflicts) {
expect(cliOutput.indexOf(conflict) > 0).toBe(true) 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