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