Unverified Commit a28f7acf authored by Jamiboy Mohammad's avatar Jamiboy Mohammad Committed by GitHub

Enable build diagnostic suites in deploy mode (#99402)

## Summary

Enable seven e2e suites to validate build diagnostics on deployments.
Expected build failures now use deferred `next.start()` rejection and
retained build logs, preserving the routing, codemod and `after()`
diagnostics. The successful `generateStaticParams` case uses deployment
startup and accepts timestamp-prefixed build events.

## Verification

- Production: all seven suites passed with Turbopack and Webpack,
including the existing diagnostic snapshots.
- Development: all six applicable suites passed with both bundlers; the
existing production-only suite remains skipped in dev.
- Confirmed build-event parsing preserves payloads for plain and
timestamp-prefixed logs.
- Formatting and ESLint passed. Deploy execution remains for CI.

<!-- NEXT_JS_LLM -->
parent 46586eea
...@@ -2,14 +2,11 @@ import { nextTestSetup } from 'e2e-utils' ...@@ -2,14 +2,11 @@ import { nextTestSetup } from 'e2e-utils'
import stripAnsi from 'strip-ansi' import stripAnsi from 'strip-ansi'
describe('canonical-interception-routes', () => { describe('canonical-interception-routes', () => {
const { next, isNextDev, isTurbopack, skipped } = nextTestSetup({ const { next, isNextDev, isTurbopack } = nextTestSetup({
files: __dirname, files: __dirname,
skipStart: true, skipStart: true,
skipDeployment: true,
}) })
if (skipped) return
it('requires a canonical hard-navigation route for every interception route', async () => { it('requires a canonical hard-navigation route for every interception route', async () => {
if (isNextDev) { if (isNextDev) {
await next.start() await next.start()
...@@ -45,8 +42,8 @@ describe('canonical-interception-routes', () => { ...@@ -45,8 +42,8 @@ describe('canonical-interception-routes', () => {
expectDefaultStrictRouteMatchingWarning(next.cliOutput) expectDefaultStrictRouteMatchingWarning(next.cliOutput)
} else { } else {
const { exitCode, cliOutput } = await next.build() await expect(next.start()).rejects.toThrow()
expect(exitCode).toBe(1) const cliOutput = next.cliOutput
expect(extractMissingCanonicalRoutesError(cliOutput)) expect(extractMissingCanonicalRoutesError(cliOutput))
.toMatchInlineSnapshot(` .toMatchInlineSnapshot(`
...@@ -57,7 +54,7 @@ describe('canonical-interception-routes', () => { ...@@ -57,7 +54,7 @@ describe('canonical-interception-routes', () => {
`) `)
expectDefaultStrictRouteMatchingWarning(cliOutput) expectDefaultStrictRouteMatchingWarning(cliOutput)
} }
}) }, 240_000)
}) })
function expectDefaultStrictRouteMatchingWarning(output: string): void { function expectDefaultStrictRouteMatchingWarning(output: string): void {
......
...@@ -7,12 +7,10 @@ import { ...@@ -7,12 +7,10 @@ import {
} from 'next-test-utils' } from 'next-test-utils'
describe('app-dir - error-on-next-codemod-comment', () => { describe('app-dir - error-on-next-codemod-comment', () => {
const { next, isNextDev, skipped } = nextTestSetup({ const { next, isNextDev } = nextTestSetup({
files: __dirname, files: __dirname,
skipStart: true, skipStart: true,
skipDeployment: true,
}) })
if (skipped) return
if (isNextDev) { if (isNextDev) {
beforeAll(async () => { beforeAll(async () => {
...@@ -121,11 +119,10 @@ describe('app-dir - error-on-next-codemod-comment', () => { ...@@ -121,11 +119,10 @@ describe('app-dir - error-on-next-codemod-comment', () => {
}) })
} else { } else {
it('should fail the build with next build', async () => { it('should fail the build with next build', async () => {
const res = await next.build() await expect(next.start()).rejects.toThrow()
expect(res.exitCode).toBe(1) expect(next.cliOutput).toContain(
expect(res.cliOutput).toContain(
'You have an unresolved @next/codemod comment "remove jsx of next line" that needs review.' 'You have an unresolved @next/codemod comment "remove jsx of next line" that needs review.'
) )
}) }, 240_000)
} }
}) })
...@@ -2,14 +2,11 @@ import { nextTestSetup } from 'e2e-utils' ...@@ -2,14 +2,11 @@ import { nextTestSetup } from 'e2e-utils'
import stripAnsi from 'strip-ansi' import stripAnsi from 'strip-ansi'
describe('incompatible-parallel-route-slots', () => { describe('incompatible-parallel-route-slots', () => {
const { next, isNextDev, isTurbopack, skipped } = nextTestSetup({ const { next, isNextDev, isTurbopack } = nextTestSetup({
files: __dirname, files: __dirname,
skipStart: true, skipStart: true,
skipDeployment: true,
}) })
if (skipped) return
it('reports the layout whose slots cannot render the same URLs', async () => { it('reports the layout whose slots cannot render the same URLs', async () => {
if (isNextDev) { if (isNextDev) {
await next.start() await next.start()
...@@ -55,8 +52,8 @@ describe('incompatible-parallel-route-slots', () => { ...@@ -55,8 +52,8 @@ describe('incompatible-parallel-route-slots', () => {
) )
expectDefaultStrictRouteMatchingWarning(next.cliOutput) expectDefaultStrictRouteMatchingWarning(next.cliOutput)
} else { } else {
const { exitCode, cliOutput } = await next.build() await expect(next.start()).rejects.toThrow()
expect(exitCode).toBe(1) const cliOutput = next.cliOutput
expect(extractIncompatibleSlotsError(cliOutput)).toMatchInlineSnapshot(` expect(extractIncompatibleSlotsError(cliOutput)).toMatchInlineSnapshot(`
"The following layouts have parallel route slots that cannot render the same URLs: "The following layouts have parallel route slots that cannot render the same URLs:
...@@ -74,7 +71,7 @@ describe('incompatible-parallel-route-slots', () => { ...@@ -74,7 +71,7 @@ describe('incompatible-parallel-route-slots', () => {
) )
expectDefaultStrictRouteMatchingWarning(cliOutput) expectDefaultStrictRouteMatchingWarning(cliOutput)
} }
}) }, 240_000)
}) })
function expectDefaultStrictRouteMatchingWarning(output: string): void { function expectDefaultStrictRouteMatchingWarning(output: string): void {
......
/* eslint-env jest */ /* eslint-env jest */
import { isNextDev, nextTestSetup } from 'e2e-utils' import { isNextDev, nextTestSetup } from 'e2e-utils'
// This test relies on next.build() so it can't work in dev mode. // Static prerendering errors are only reported during production builds.
const _describe = isNextDev ? describe.skip : describe const _describe = isNextDev ? describe.skip : describe
_describe('after() in static pages - thrown errors', () => { _describe('after() in static pages - thrown errors', () => {
const { next, skipped } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
skipStart: true, skipStart: true,
skipDeployment: true, // can't access build errors in deploy tests
}) })
if (skipped) return
it('fails the build if an error is thrown inside after', async () => { it('fails the build if an error is thrown inside after', async () => {
const buildResult = await next.build() await expect(next.start()).rejects.toThrow()
expect(buildResult?.exitCode).toBe(1)
{ {
const path = '/page-throws-in-after/callback' const path = '/page-throws-in-after/callback'
...@@ -56,5 +52,5 @@ _describe('after() in static pages - thrown errors', () => { ...@@ -56,5 +52,5 @@ _describe('after() in static pages - thrown errors', () => {
`My cool error thrown inside after on route "${path}"` `My cool error thrown inside after on route "${path}"`
) )
} }
}) }, 240_000)
}) })
...@@ -6,14 +6,11 @@ import { ...@@ -6,14 +6,11 @@ import {
} from '../../../../lib/next-test-utils' } from '../../../../lib/next-test-utils'
describe('after() in generateStaticParams - thrown errors', () => { describe('after() in generateStaticParams - thrown errors', () => {
const { next, skipped, isNextDev } = nextTestSetup({ const { next, isNextDev } = nextTestSetup({
files: __dirname, files: __dirname,
skipStart: true, skipStart: true,
skipDeployment: true, // can't access build errors in deploy tests
}) })
if (skipped) return
if (isNextDev) { if (isNextDev) {
it('shows the error overlay if an error is thrown inside after', async () => { it('shows the error overlay if an error is thrown inside after', async () => {
await next.start() await next.start()
...@@ -26,8 +23,7 @@ describe('after() in generateStaticParams - thrown errors', () => { ...@@ -26,8 +23,7 @@ describe('after() in generateStaticParams - thrown errors', () => {
}) })
} else { } else {
it('fails the build if an error is thrown inside after', async () => { it('fails the build if an error is thrown inside after', async () => {
const buildResult = await next.build() await expect(next.start()).rejects.toThrow()
expect(buildResult?.exitCode).toBe(1)
const route = '/callback/[myParam]' const route = '/callback/[myParam]'
expect(next.cliOutput).toContain( expect(next.cliOutput).toContain(
...@@ -36,6 +32,6 @@ describe('after() in generateStaticParams - thrown errors', () => { ...@@ -36,6 +32,6 @@ describe('after() in generateStaticParams - thrown errors', () => {
expect(next.cliOutput).toContain( expect(next.cliOutput).toContain(
`My cool error thrown inside after on route "${route}"` `My cool error thrown inside after on route "${route}"`
) )
}) }, 240_000)
} }
}) })
...@@ -4,14 +4,11 @@ import * as Log from './utils/log' ...@@ -4,14 +4,11 @@ import * as Log from './utils/log'
import { waitForNoRedbox, retry } from '../../../../lib/next-test-utils' import { waitForNoRedbox, retry } from '../../../../lib/next-test-utils'
describe('after() in generateStaticParams', () => { describe('after() in generateStaticParams', () => {
const { next, isNextDev, skipped } = nextTestSetup({ const { next, isNextDev } = nextTestSetup({
files: __dirname, files: __dirname,
skipDeployment: true, // reading CLI logs to observe after
skipStart: true, skipStart: true,
}) })
if (skipped) return
let currentCliOutputIndex = 0 let currentCliOutputIndex = 0
beforeEach(() => { beforeEach(() => {
currentCliOutputIndex = next.cliOutput.length currentCliOutputIndex = next.cliOutput.length
...@@ -49,8 +46,7 @@ describe('after() in generateStaticParams', () => { ...@@ -49,8 +46,7 @@ describe('after() in generateStaticParams', () => {
}) })
} else { } else {
it('runs after callbacks for each page during build', async () => { it('runs after callbacks for each page during build', async () => {
const buildResult = await next.build() await next.start()
expect(buildResult?.exitCode).toBe(0)
{ {
// after should run at build time // after should run at build time
...@@ -62,6 +58,6 @@ describe('after() in generateStaticParams', () => { ...@@ -62,6 +58,6 @@ describe('after() in generateStaticParams', () => {
source: '[generateStaticParams] /two/[myParam]', source: '[generateStaticParams] /two/[myParam]',
}) })
} }
}) }, 240_000)
} }
}) })
...@@ -6,7 +6,8 @@ export function readCliLogs(/** @type {string} */ output) { ...@@ -6,7 +6,8 @@ export function readCliLogs(/** @type {string} */ output) {
return output return output
.split('\n') .split('\n')
.map((line) => { .map((line) => {
const match = line.match(/^<test-log>(?<value>.+?)<\/test-log>$/) // Deployment build logs can prefix each line with a timestamp.
const match = line.match(/<test-log>(?<value>.+?)<\/test-log>$/)
if (!match) { if (!match) {
return null return null
} }
......
...@@ -2,14 +2,11 @@ import { nextTestSetup } from 'e2e-utils' ...@@ -2,14 +2,11 @@ import { nextTestSetup } from 'e2e-utils'
import stripAnsi from 'strip-ansi' import stripAnsi from 'strip-ansi'
describe('unmatched-app-pages', () => { describe('unmatched-app-pages', () => {
const { next, isNextDev, isTurbopack, skipped } = nextTestSetup({ const { next, isNextDev, isTurbopack } = nextTestSetup({
files: __dirname, files: __dirname,
skipStart: true, skipStart: true,
skipDeployment: true,
}) })
if (skipped) return
it('reports every page excluded from all complete routes', async () => { it('reports every page excluded from all complete routes', async () => {
if (isNextDev) { if (isNextDev) {
await next.start() await next.start()
...@@ -50,8 +47,8 @@ describe('unmatched-app-pages', () => { ...@@ -50,8 +47,8 @@ describe('unmatched-app-pages', () => {
expectDefaultStrictRouteMatchingWarning(next.cliOutput) expectDefaultStrictRouteMatchingWarning(next.cliOutput)
} else { } else {
const { exitCode, cliOutput } = await next.build() await expect(next.start()).rejects.toThrow()
expect(exitCode).toBe(1) const cliOutput = next.cliOutput
expect(extractUnmatchedPagesError(cliOutput)).toMatchInlineSnapshot(` expect(extractUnmatchedPagesError(cliOutput)).toMatchInlineSnapshot(`
"The following page files do not match any complete route: "The following page files do not match any complete route:
...@@ -68,7 +65,7 @@ describe('unmatched-app-pages', () => { ...@@ -68,7 +65,7 @@ describe('unmatched-app-pages', () => {
`) `)
expectDefaultStrictRouteMatchingWarning(cliOutput) expectDefaultStrictRouteMatchingWarning(cliOutput)
} }
}) }, 240_000)
}) })
function expectDefaultStrictRouteMatchingWarning(output: string): void { function expectDefaultStrictRouteMatchingWarning(output: string): void {
......
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