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)
}
})
})
......
import { nextTestSetup } from 'e2e-utils'
import path from 'path'
import { FileRef, nextTestSetup } from 'e2e-utils'
import {
retry,
waitForRedbox,
......@@ -6,9 +7,6 @@ import {
getRedboxSource,
} from 'next-test-utils'
// 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('cache-components-segment-configs', () => {
const { next, isNextDev, isTurbopack } = nextTestSetup({
files: __dirname + '/fixtures/default',
......@@ -16,13 +14,9 @@ describe('cache-components-segment-configs', () => {
})
it("it should error when using segment configs that aren't supported by cacheComponents", async () => {
try {
if (isNextDev) {
await next.start()
} catch {
// we expect the build to fail
}
if (isNextDev) {
const browser = await next.browser('/revalidate')
await waitForRedbox(browser)
const redbox = {
......@@ -42,124 +36,127 @@ describe('cache-components-segment-configs', () => {
expect(redbox.source).toContain(
'"revalidate" is not compatible with `nextConfig.cacheComponents`. Please remove it.'
)
} else {
expect(next.cliOutput).toContain('./app/dynamic-params/[slug]/page.tsx')
expect(next.cliOutput).toContain(
'"dynamicParams" is not compatible with `nextConfig.cacheComponents`. Please remove it.'
)
expect(next.cliOutput).toContain('./app/dynamic/nested/page.tsx')
expect(next.cliOutput).toContain('./app/dynamic/page.tsx')
expect(next.cliOutput).toContain(
'"dynamic" is not compatible with `nextConfig.cacheComponents`. Please remove it.'
)
return
}
expect(next.cliOutput).toContain('./app/fetch-cache/page.tsx')
expect(next.cliOutput).toContain(
'"fetchCache" is not compatible with `nextConfig.cacheComponents`. Please remove it.'
)
// The build is expected to fail.
await expect(next.start()).rejects.toThrow()
expect(next.cliOutput).toContain('./app/revalidate/page.tsx')
expect(next.cliOutput).toContain(
'"revalidate" is not compatible with `nextConfig.cacheComponents`. Please remove it.'
expect(next.cliOutput).toContain('./app/dynamic-params/[slug]/page.tsx')
expect(next.cliOutput).toContain(
'"dynamicParams" is not compatible with `nextConfig.cacheComponents`. Please remove it.'
)
expect(next.cliOutput).toContain('./app/dynamic/nested/page.tsx')
expect(next.cliOutput).toContain('./app/dynamic/page.tsx')
expect(next.cliOutput).toContain(
'"dynamic" is not compatible with `nextConfig.cacheComponents`. Please remove it.'
)
expect(next.cliOutput).toContain('./app/fetch-cache/page.tsx')
expect(next.cliOutput).toContain(
'"fetchCache" is not compatible with `nextConfig.cacheComponents`. Please remove it.'
)
expect(next.cliOutput).toContain('./app/revalidate/page.tsx')
expect(next.cliOutput).toContain(
'"revalidate" is not compatible with `nextConfig.cacheComponents`. Please remove it.'
)
// The remaining fixtures opt into `export const runtime = 'edge'` (the
// `runtime` page and the metadata convention files, which compile to
// route handlers and accept the same route segment configs). `next build`
// prints only the first five webpack errors and appends the edge
// compiler's errors last, so the five Node-runtime page errors above fill
// that limit and these edge-runtime errors are truncated from webpack's
// output. They're only asserted under Turbopack, which reports every
// build error.
if (isTurbopack) {
expect(next.cliOutput).toContain('./app/runtime/page.tsx')
expect(next.cliOutput).toContain('./app/metadata/icon.tsx')
expect(next.cliOutput).toContain('./app/metadata/apple-icon.tsx')
expect(next.cliOutput).toContain('./app/metadata/opengraph-image.tsx')
expect(next.cliOutput).toContain('./app/metadata/twitter-image.tsx')
expect(next.cliOutput).toContain('./app/metadata/sitemap.ts')
// Emitted once for each fixture that exports `runtime`:
// `runtime/page.tsx`, `multiple/page.tsx`, and the five `metadata/*`
// convention files.
expect(next.cliOutput).toIncludeRepeated(
'"runtime" is not compatible with `nextConfig.cacheComponents`. Please remove it.',
7
)
}
}, 240_000)
})
describe('cache-components-segment-configs layout propagation', () => {
const { next, isNextDev, isTurbopack } = nextTestSetup({
files: __dirname + '/fixtures/default',
// The root layout exports `runtime`, so the "runtime" segment config
// propagates to each page that uses it.
overrideFiles: {
'app/layout.tsx': new FileRef(
path.join(__dirname, 'fixtures/layout-runtime/app/layout.tsx')
),
},
skipStart: true,
})
it('should propagate configurations from layouts to pages', async () => {
if (isNextDev) {
await next.start()
const browser = await next.browser('/revalidate')
await waitForRedbox(browser)
const redbox = {
description: await getRedboxDescription(browser),
source: await getRedboxSource(browser),
}
// The remaining fixtures opt into `export const runtime = 'edge'` (the
// `runtime` page and the metadata convention files, which compile to
// route handlers and accept the same route segment configs). `next build`
// prints only the first five webpack errors and appends the edge
// compiler's errors last, so the five Node-runtime page errors above fill
// that limit and these edge-runtime errors are truncated from webpack's
// output. They're only asserted under Turbopack, which reports every
// build error.
if (isTurbopack) {
expect(next.cliOutput).toContain('./app/runtime/page.tsx')
expect(next.cliOutput).toContain('./app/metadata/icon.tsx')
expect(next.cliOutput).toContain('./app/metadata/apple-icon.tsx')
expect(next.cliOutput).toContain('./app/metadata/opengraph-image.tsx')
expect(next.cliOutput).toContain('./app/metadata/twitter-image.tsx')
expect(next.cliOutput).toContain('./app/metadata/sitemap.ts')
// Emitted once for each fixture that exports `runtime`:
// `runtime/page.tsx`, `multiple/page.tsx`, and the five `metadata/*`
// convention files.
expect(next.cliOutput).toIncludeRepeated(
'"runtime" is not compatible with `nextConfig.cacheComponents`. Please remove it.',
7
// The page-level error is shown first in the redbox, but
// the layout error is also present in the CLI output.
expect(redbox.description).toMatchInlineSnapshot(
`"Route segment config "revalidate" is not compatible with \`nextConfig.cacheComponents\`. Please remove it."`
)
} else {
expect(redbox.description).toMatchInlineSnapshot(
`" x Route segment config "runtime" is not compatible with \`nextConfig.cacheComponents\`. Please remove it."`
)
}
expect(redbox.source).toContain(
'is not compatible with `nextConfig.cacheComponents`. Please remove it.'
)
// Verify that the "runtime" error from the layout propagation
// is present in the CLI output even if it's not the first error
// shown in the redbox.
expect(next.cliOutput).toContain(
'"runtime" is not compatible with `nextConfig.cacheComponents`. Please remove it.'
)
return
}
})
it('should propagate configurations from layouts to pages', async () => {
// patch the root layout. We expect the "dynamic" segment config to now be part of
// each sub-page that uses this layout.
await next.patchFile(
'app/layout.tsx',
(content) => {
return `
export const runtime = 'nodejs';
${content}
`
},
async () => {
try {
await next.start()
} catch {
// we expect the build to fail
}
if (isNextDev) {
const browser = await next.browser('/revalidate')
await waitForRedbox(browser)
const redbox = {
description: await getRedboxDescription(browser),
source: await getRedboxSource(browser),
}
if (isTurbopack) {
// The page-level error is shown first in the redbox, but
// the layout error is also present in the CLI output.
expect(redbox.description).toMatchInlineSnapshot(
`"Route segment config "revalidate" is not compatible with \`nextConfig.cacheComponents\`. Please remove it."`
)
} else {
expect(redbox.description).toMatchInlineSnapshot(
`" x Route segment config "runtime" is not compatible with \`nextConfig.cacheComponents\`. Please remove it."`
)
}
expect(redbox.source).toContain(
'is not compatible with `nextConfig.cacheComponents`. Please remove it.'
)
// Verify that the "runtime" error from the layout propagation
// is present in the CLI output even if it's not the first error
// shown in the redbox.
expect(next.cliOutput).toContain(
'"runtime" is not compatible with `nextConfig.cacheComponents`. Please remove it.'
)
} else {
await retry(async () => {
expect(next.cliOutput).toContain(
'"runtime" is not compatible with `nextConfig.cacheComponents`. Please remove it.'
)
// the stack trace is different between turbopack/webpack
if (isTurbopack) {
expectLinesToAppearTogether(next.cliOutput, [
'./app/layout.tsx:2:24',
])
} else {
expectLinesToAppearTogether(next.cliOutput, [
'Import trace for requested module:',
'./app/fetch-cache/page.tsx',
'./app/layout.tsx',
])
}
})
}
// The build is expected to fail.
await expect(next.start()).rejects.toThrow()
await retry(async () => {
expect(next.cliOutput).toContain(
'"runtime" is not compatible with `nextConfig.cacheComponents`. Please remove it.'
)
// the stack trace is different between turbopack/webpack
if (isTurbopack) {
expectLinesToAppearTogether(next.cliOutput, ['./app/layout.tsx:1:14'])
} else {
expectLinesToAppearTogether(next.cliOutput, [
'Import trace for requested module:',
'./app/fetch-cache/page.tsx',
'./app/layout.tsx',
])
}
)
})
})
}, 240_000)
})
function expectLinesToAppearTogether(output: string, lines: string[]) {
......
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