Unverified Commit 8b583887 authored by Jamiboy Mohammad's avatar Jamiboy Mohammad Committed by GitHub

test: enable build-error suites in deploy mode (#100482)

## Summary

Enables five suites in deploy mode whose builds are expected to fail, or
whose setup used `patchFile` or a runtime-only env.

- **`use-cache-unknown-cache-kind`,
`use-cache-without-experimental-flag`,
`proxy-and-middleware-conflict`**: outside dev the tests assert
`next.start()` rejects and read the build diagnostics from
`next.cliOutput`, with `toContain` checks in deploy mode and the
existing snapshots locally. The first two previously branched on
`isNextStart`, so in deploy mode their dev-only `createSandbox` tests
ran instead. `proxy-and-middleware-conflict` drops its blanket
`skipDeployment`.
- **`cache-components-segment-configs`**: same `next.start()` rejection
pattern. The layout-propagation test used
`next.patchFile('app/layout.tsx', …)`, which deploy mode doesn't
support. It now has its own `nextTestSetup` whose `overrideFiles` swaps
in `fixtures/layout-runtime/app/layout.tsx`. The Turbopack location
assertion moves from `./app/layout.tsx:2:24` to `:1:14` to match the
fixture file.
- **`cache-components-errors/console-patch`**: with the gate removed in
the Sept 9 retry runs, the deployment failed because
`NODE_OPTIONS='--require ./patch-console.js'` is forwarded as both a
build and a runtime env, and Vercel's own CLI process crashed with
`Cannot find module './patch-console.js'`. In deploy mode the preload is
now scoped to the build via `buildCommand`; dev and start keep `env`.
The deploy branch asserts the deployment succeeds (so the build didn't
fail on the patched `console.log`) and that the patched log line appears
in the build output. The local snapshots are unchanged.

## Verification

- Prettier and ESLint on the changed files.
- Ran all five suites locally against this branch's local packages;
every suite passed in each of:
  - `next dev` and `next start`, with Turbopack and with webpack
  - deploy, Turbopack + adapter (the PR deploy job's variant)
  - deploy, Webpack legacy (one of the release workflow's variants)
- Not run: Turbopack legacy deploy (`NEXT_ENABLE_ADAPTER=0`); my account
lacks deploy access to the Turbopack test team's project.

<!-- NEXT_JS_LLM -->
parent 3dd7baa5
import { isNextDev, nextTestSetup } from 'e2e-utils'
import { isNextDeploy, isNextDev, nextTestSetup } from 'e2e-utils'
import { getPrerenderOutput } from './utils'
import { retry } from 'next-test-utils'
// TODO(deploy-test-completion): Re-enable this suite in deploy mode.
// It likely asserts local CLI or runtime output that deploy tests do not expose.
// @force-gate !deploy
describe('Cache Components Errors', () => {
const { next, isTurbopack, isNextStart } = nextTestSetup({
files: __dirname + '/fixtures/console-patch',
skipStart: !isNextDev,
env: {
NODE_OPTIONS: '--require ./patch-console.js',
},
// In deploy mode, `env` also reaches the deploy tooling and the deployed
// functions, where `./patch-console.js` can't be resolved, so only the
// build gets the patched console there.
...(isNextDeploy
? {
buildCommand:
"NODE_OPTIONS='--require ./patch-console.js' next build",
}
: {
env: {
NODE_OPTIONS: '--require ./patch-console.js',
},
}),
})
let cliOutputLength: number
......@@ -52,6 +59,17 @@ describe('Cache Components Errors', () => {
})
} else {
it('does not fail the build for Sync IO if console.log is patched to call new Date() internally', async () => {
if (isNextDeploy) {
// The deployment only succeeds if the build does.
await next.start()
expect(next.cliOutput).toContain(
'[<timestamp>] This is a console log from a server component page'
)
expect(next.cliOutput).not.toContain('Build error occurred')
return
}
try {
await next.build()
} catch {}
......@@ -75,7 +93,7 @@ describe('Cache Components Errors', () => {
[<timestamp>]"
`)
}
})
}, 240_000)
}
})
})
......
export const runtime = 'nodejs'
export default function Root({ children }: { children: React.ReactNode }) {
return (
<html>
<body>
<main>{children}</main>
</body>
</html>
)
}
......@@ -2,16 +2,11 @@ import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
describe('proxy-and-middleware-conflict', () => {
const { next, isNextDev, skipped } = nextTestSetup({
const { next, isNextDev } = nextTestSetup({
files: __dirname,
skipStart: true,
skipDeployment: true,
})
if (skipped) {
return
}
if (isNextDev) {
beforeAll(async () => {
// The dev bundler discovers both files during its first compile,
......@@ -20,21 +15,17 @@ describe('proxy-and-middleware-conflict', () => {
// we just need the boot-time scan to have run.
await next.start()
})
} else {
beforeAll(async () => {
try {
await next.build()
} catch {
// Expect build error.
}
})
}
it('should report that both middleware and proxy files are present', async () => {
if (!isNextDev) {
await expect(next.start()).rejects.toThrow()
}
await retry(() => {
expect(next.cliOutput).toContain(
'are detected. Please use "./proxy.page.ts" only.'
)
})
})
}, 240_000)
})
......@@ -9,24 +9,25 @@ import {
import stripAnsi from 'strip-ansi'
import { createSandbox } from 'development-sandbox'
// TODO(deploy-test-completion): Re-enable this suite in deploy mode.
// It likely expects a local build failure instead of a successful deployment.
// @force-gate !deploy
describe('use-cache-unknown-cache-kind', () => {
const { next, isNextStart, isTurbopack, isRspack } = nextTestSetup({
files: __dirname,
skipStart: process.env.NEXT_TEST_MODE !== 'dev',
})
if (isNextStart) {
beforeAll(async () => {
await next.build()
const { next, isNextDev, isNextDeploy, isTurbopack, isRspack } =
nextTestSetup({
files: __dirname,
skipStart: process.env.NEXT_TEST_MODE !== 'dev',
})
if (!isNextDev) {
it('should fail the build with an error', async () => {
await expect(next.start()).rejects.toThrow()
const buildOutput = getBuildOutput(next.cliOutput)
if (isTurbopack) {
if (isNextDeploy) {
expect(next.cliOutput).toContain(
'Unknown cache kind "custom". Please configure a cache handler for this kind in the `cacheHandlers` object in your Next.js config.'
)
expect(next.cliOutput).toContain('./app/page.tsx')
expect(next.cliOutput).toContain("'use cache: custom'")
} else if (isTurbopack) {
expect(buildOutput).toMatchInlineSnapshot(`
"Error: Turbopack build failed with 1 error:
./app/page.tsx:1:1
......@@ -87,7 +88,7 @@ describe('use-cache-unknown-cache-kind', () => {
"
`)
}
})
}, 240_000)
it('should not fail the build for default cache kinds', async () => {
expect(next.cliOutput).not.toInclude('Unknown cache kind "remote"')
......
......@@ -13,21 +13,28 @@ const nextConfigWithUseCache: NextConfig = {
experimental: { useCache: true },
}
// TODO(deploy-test-completion): Re-enable this suite in deploy mode.
// It likely expects a local build failure instead of a successful deployment.
// @force-gate !deploy
describe('use-cache-without-experimental-flag', () => {
const { next, isNextStart, isTurbopack, isRspack } = nextTestSetup({
files: __dirname,
skipStart: process.env.NEXT_TEST_MODE !== 'dev',
})
const { next, isNextDev, isNextDeploy, isTurbopack, isRspack } =
nextTestSetup({
files: __dirname,
skipStart: process.env.NEXT_TEST_MODE !== 'dev',
})
if (isNextStart) {
if (!isNextDev) {
it('should fail the build with an error', async () => {
const { cliOutput } = await next.build()
const buildOutput = getBuildOutput(cliOutput)
await expect(next.start()).rejects.toThrow()
const buildOutput = getBuildOutput(next.cliOutput)
if (isTurbopack) {
if (isNextDeploy) {
expect(next.cliOutput).toContain(
'To use "use cache", please enable the feature flag `cacheComponents` in your Next.js config.'
)
expect(next.cliOutput).toContain(
'Read more: https://nextjs.org/docs/app/api-reference/directives/use-cache#usage'
)
expect(next.cliOutput).toContain('./app/page.tsx')
expect(next.cliOutput).toContain("'use cache'")
} else if (isTurbopack) {
expect(buildOutput).toContain(
'To use "use cache", please enable the feature flag `cacheComponents` in your Next.js config.'
)
......@@ -88,7 +95,7 @@ describe('use-cache-without-experimental-flag', () => {
"
`)
}
})
}, 240_000)
} else {
it('should show a build error', async () => {
const browser = await next.browser('/')
......
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