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 { getPrerenderOutput } from './utils'
import { retry } from 'next-test-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', () => { describe('Cache Components Errors', () => {
const { next, isTurbopack, isNextStart } = nextTestSetup({ const { next, isTurbopack, isNextStart } = nextTestSetup({
files: __dirname + '/fixtures/console-patch', files: __dirname + '/fixtures/console-patch',
skipStart: !isNextDev, skipStart: !isNextDev,
// 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: { env: {
NODE_OPTIONS: '--require ./patch-console.js', NODE_OPTIONS: '--require ./patch-console.js',
}, },
}),
}) })
let cliOutputLength: number let cliOutputLength: number
...@@ -52,6 +59,17 @@ describe('Cache Components Errors', () => { ...@@ -52,6 +59,17 @@ describe('Cache Components Errors', () => {
}) })
} else { } else {
it('does not fail the build for Sync IO if console.log is patched to call new Date() internally', async () => { 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 { try {
await next.build() await next.build()
} catch {} } catch {}
...@@ -75,7 +93,7 @@ describe('Cache Components Errors', () => { ...@@ -75,7 +93,7 @@ describe('Cache Components Errors', () => {
[<timestamp>]" [<timestamp>]"
`) `)
} }
}) }, 240_000)
} }
}) })
}) })
......
import { nextTestSetup } from 'e2e-utils' import path from 'path'
import { FileRef, nextTestSetup } from 'e2e-utils'
import { import {
retry, retry,
waitForRedbox, waitForRedbox,
...@@ -6,9 +7,6 @@ import { ...@@ -6,9 +7,6 @@ import {
getRedboxSource, getRedboxSource,
} from 'next-test-utils' } 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', () => { describe('cache-components-segment-configs', () => {
const { next, isNextDev, isTurbopack } = nextTestSetup({ const { next, isNextDev, isTurbopack } = nextTestSetup({
files: __dirname + '/fixtures/default', files: __dirname + '/fixtures/default',
...@@ -16,13 +14,9 @@ describe('cache-components-segment-configs', () => { ...@@ -16,13 +14,9 @@ describe('cache-components-segment-configs', () => {
}) })
it("it should error when using segment configs that aren't supported by cacheComponents", async () => { it("it should error when using segment configs that aren't supported by cacheComponents", async () => {
try { if (isNextDev) {
await next.start() await next.start()
} catch {
// we expect the build to fail
}
if (isNextDev) {
const browser = await next.browser('/revalidate') const browser = await next.browser('/revalidate')
await waitForRedbox(browser) await waitForRedbox(browser)
const redbox = { const redbox = {
...@@ -42,7 +36,12 @@ describe('cache-components-segment-configs', () => { ...@@ -42,7 +36,12 @@ describe('cache-components-segment-configs', () => {
expect(redbox.source).toContain( expect(redbox.source).toContain(
'"revalidate" is not compatible with `nextConfig.cacheComponents`. Please remove it.' '"revalidate" is not compatible with `nextConfig.cacheComponents`. Please remove it.'
) )
} else { return
}
// The build is expected to fail.
await expect(next.start()).rejects.toThrow()
expect(next.cliOutput).toContain('./app/dynamic-params/[slug]/page.tsx') expect(next.cliOutput).toContain('./app/dynamic-params/[slug]/page.tsx')
expect(next.cliOutput).toContain( expect(next.cliOutput).toContain(
'"dynamicParams" is not compatible with `nextConfig.cacheComponents`. Please remove it.' '"dynamicParams" is not compatible with `nextConfig.cacheComponents`. Please remove it.'
...@@ -88,28 +87,26 @@ describe('cache-components-segment-configs', () => { ...@@ -88,28 +87,26 @@ describe('cache-components-segment-configs', () => {
7 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 () => { it('should propagate configurations from layouts to pages', async () => {
// patch the root layout. We expect the "dynamic" segment config to now be part of if (isNextDev) {
// 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() await next.start()
} catch {
// we expect the build to fail
}
if (isNextDev) {
const browser = await next.browser('/revalidate') const browser = await next.browser('/revalidate')
await waitForRedbox(browser) await waitForRedbox(browser)
const redbox = { const redbox = {
...@@ -137,7 +134,12 @@ describe('cache-components-segment-configs', () => { ...@@ -137,7 +134,12 @@ describe('cache-components-segment-configs', () => {
expect(next.cliOutput).toContain( expect(next.cliOutput).toContain(
'"runtime" is not compatible with `nextConfig.cacheComponents`. Please remove it.' '"runtime" is not compatible with `nextConfig.cacheComponents`. Please remove it.'
) )
} else { return
}
// The build is expected to fail.
await expect(next.start()).rejects.toThrow()
await retry(async () => { await retry(async () => {
expect(next.cliOutput).toContain( expect(next.cliOutput).toContain(
'"runtime" is not compatible with `nextConfig.cacheComponents`. Please remove it.' '"runtime" is not compatible with `nextConfig.cacheComponents`. Please remove it.'
...@@ -145,9 +147,7 @@ describe('cache-components-segment-configs', () => { ...@@ -145,9 +147,7 @@ describe('cache-components-segment-configs', () => {
// the stack trace is different between turbopack/webpack // the stack trace is different between turbopack/webpack
if (isTurbopack) { if (isTurbopack) {
expectLinesToAppearTogether(next.cliOutput, [ expectLinesToAppearTogether(next.cliOutput, ['./app/layout.tsx:1:14'])
'./app/layout.tsx:2:24',
])
} else { } else {
expectLinesToAppearTogether(next.cliOutput, [ expectLinesToAppearTogether(next.cliOutput, [
'Import trace for requested module:', 'Import trace for requested module:',
...@@ -156,10 +156,7 @@ describe('cache-components-segment-configs', () => { ...@@ -156,10 +156,7 @@ describe('cache-components-segment-configs', () => {
]) ])
} }
}) })
} }, 240_000)
}
)
})
}) })
function expectLinesToAppearTogether(output: string, lines: string[]) { 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' ...@@ -2,16 +2,11 @@ import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils' import { retry } from 'next-test-utils'
describe('proxy-and-middleware-conflict', () => { describe('proxy-and-middleware-conflict', () => {
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 () => {
// The dev bundler discovers both files during its first compile, // The dev bundler discovers both files during its first compile,
...@@ -20,21 +15,17 @@ describe('proxy-and-middleware-conflict', () => { ...@@ -20,21 +15,17 @@ describe('proxy-and-middleware-conflict', () => {
// we just need the boot-time scan to have run. // we just need the boot-time scan to have run.
await next.start() 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 () => { it('should report that both middleware and proxy files are present', async () => {
if (!isNextDev) {
await expect(next.start()).rejects.toThrow()
}
await retry(() => { await retry(() => {
expect(next.cliOutput).toContain( expect(next.cliOutput).toContain(
'are detected. Please use "./proxy.page.ts" only.' 'are detected. Please use "./proxy.page.ts" only.'
) )
}) })
}) }, 240_000)
}) })
...@@ -9,24 +9,25 @@ import { ...@@ -9,24 +9,25 @@ import {
import stripAnsi from 'strip-ansi' import stripAnsi from 'strip-ansi'
import { createSandbox } from 'development-sandbox' 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', () => { describe('use-cache-unknown-cache-kind', () => {
const { next, isNextStart, isTurbopack, isRspack } = nextTestSetup({ const { next, isNextDev, isNextDeploy, isTurbopack, isRspack } =
nextTestSetup({
files: __dirname, files: __dirname,
skipStart: process.env.NEXT_TEST_MODE !== 'dev', skipStart: process.env.NEXT_TEST_MODE !== 'dev',
}) })
if (isNextStart) { if (!isNextDev) {
beforeAll(async () => {
await next.build()
})
it('should fail the build with an error', async () => { it('should fail the build with an error', async () => {
await expect(next.start()).rejects.toThrow()
const buildOutput = getBuildOutput(next.cliOutput) 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(` expect(buildOutput).toMatchInlineSnapshot(`
"Error: Turbopack build failed with 1 error: "Error: Turbopack build failed with 1 error:
./app/page.tsx:1:1 ./app/page.tsx:1:1
...@@ -87,7 +88,7 @@ describe('use-cache-unknown-cache-kind', () => { ...@@ -87,7 +88,7 @@ describe('use-cache-unknown-cache-kind', () => {
" "
`) `)
} }
}) }, 240_000)
it('should not fail the build for default cache kinds', async () => { it('should not fail the build for default cache kinds', async () => {
expect(next.cliOutput).not.toInclude('Unknown cache kind "remote"') expect(next.cliOutput).not.toInclude('Unknown cache kind "remote"')
......
...@@ -13,21 +13,28 @@ const nextConfigWithUseCache: NextConfig = { ...@@ -13,21 +13,28 @@ const nextConfigWithUseCache: NextConfig = {
experimental: { useCache: true }, 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', () => { describe('use-cache-without-experimental-flag', () => {
const { next, isNextStart, isTurbopack, isRspack } = nextTestSetup({ const { next, isNextDev, isNextDeploy, isTurbopack, isRspack } =
nextTestSetup({
files: __dirname, files: __dirname,
skipStart: process.env.NEXT_TEST_MODE !== 'dev', skipStart: process.env.NEXT_TEST_MODE !== 'dev',
}) })
if (isNextStart) { if (!isNextDev) {
it('should fail the build with an error', async () => { it('should fail the build with an error', async () => {
const { cliOutput } = await next.build() await expect(next.start()).rejects.toThrow()
const buildOutput = getBuildOutput(cliOutput) 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( expect(buildOutput).toContain(
'To use "use cache", please enable the feature flag `cacheComponents` in your Next.js config.' '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', () => { ...@@ -88,7 +95,7 @@ describe('use-cache-without-experimental-flag', () => {
" "
`) `)
} }
}) }, 240_000)
} else { } else {
it('should show a build error', async () => { it('should show a build error', async () => {
const browser = await next.browser('/') 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