Unverified Commit 3fd5b1c0 authored by Jamiboy Mohammad's avatar Jamiboy Mohammad Committed by GitHub

test: add a `vercel` gate condition for Vercel-specific deploy tests (#99837)

## Summary

We've been enabling more e2e tests in deploy mode to increase coverage.
Some of them are written with Vercel-specific assumptions, like Vercel's
build directory, build-log format, or `vercel.json` handling. They fail
when other platforms run the deploy suite against their own adapters.

This PR adds a static `vercel` gate condition. It's true only in deploy
runs with `NEXT_TEST_DEPLOY_TARGET_VERCEL=1`, which our Vercel deploy CI
jobs set. Tests that depend on Vercel can then be skipped on other
platforms:

```ts
// @force-gate !deploy || vercel
```

The PR applies it to five recently enabled tests. This is a short-term
measure; the goal is to make these tests work on every adapter.

---------
Co-authored-by: 's avatarClaude Opus 5.5 <noreply@anthropic.com>
parent e489aae4
...@@ -93,11 +93,17 @@ Every name in a pragma must be declared in `test/lib/gate/conditions.ts` ...@@ -93,11 +93,17 @@ Every name in a pragma must be declared in `test/lib/gate/conditions.ts`
- **static** — the run's shape: `dev`, `start`, `deploy`, `mode`, `turbopack`, - **static** — the run's shape: `dev`, `start`, `deploy`, `mode`, `turbopack`,
`rspack`, `webpack`, `bundler`, `react18`, `wasm`, `linux`, `macos`, `rspack`, `webpack`, `bundler`, `react18`, `wasm`, `linux`, `macos`,
`windows`, `ci`; specialized CI variants `adapter`, `nodeMiddleware`, `windows`, `ci`; the deploy host `vercel`; specialized CI variants
`standaloneOutput`, `turbopackDev`, and `turbopackBuild`; plus the `adapter`, `nodeMiddleware`, `standaloneOutput`, `turbopackDev`, and
always-false `FIXME`/`TODO`. `turbopackBuild`; plus the always-false `FIXME`/`TODO`.
`prod` and `prefetching` are semantic aliases for `!dev` — prefer the name `prod` and `prefetching` are semantic aliases for `!dev` — prefer the name
that states _why_ the suite cannot run. that states _why_ the suite cannot run.
`vercel` is true only in a deploy run with `NEXT_TEST_DEPLOY_TARGET_VERCEL=1`,
which our CI sets on every Vercel deploy job. Other platforms run the
deploy suites through `NEXT_TEST_DEPLOY_SCRIPT_PATH` to test their
adapters, so prefer it over `deploy` when the reason is Vercel-specific:
`@force-gate !deploy || vercel` skips only other platforms, `!vercel` skips
only Vercel.
- **lazy** — a predicate over the fixture's _resolved_ `next.config` - **lazy** — a predicate over the fixture's _resolved_ `next.config`
(`cacheComponents`, `ppr`, `useOffline`, `output`, …). (`cacheComponents`, `ppr`, `useOffline`, `output`, …).
......
...@@ -908,6 +908,7 @@ jobs: ...@@ -908,6 +908,7 @@ jobs:
# Keep Next.js related env variables in sync with additionalEnv in next-deploy.ts # Keep Next.js related env variables in sync with additionalEnv in next-deploy.ts
afterBuild: | afterBuild: |
export NEXT_ENABLE_ADAPTER=1 export NEXT_ENABLE_ADAPTER=1
export NEXT_TEST_DEPLOY_TARGET_VERCEL=1
export NEXT_E2E_TEST_TIMEOUT=240000 export NEXT_E2E_TEST_TIMEOUT=240000
export __NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES=true export __NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES=true
export IS_TURBOPACK_TEST=1 export IS_TURBOPACK_TEST=1
...@@ -939,6 +940,7 @@ jobs: ...@@ -939,6 +940,7 @@ jobs:
export __NEXT_CACHE_COMPONENTS=true export __NEXT_CACHE_COMPONENTS=true
export __NEXT_EXPERIMENTAL_CACHED_NAVIGATIONS=true export __NEXT_EXPERIMENTAL_CACHED_NAVIGATIONS=true
export NEXT_ENABLE_ADAPTER=1 export NEXT_ENABLE_ADAPTER=1
export NEXT_TEST_DEPLOY_TARGET_VERCEL=1
export NEXT_EXTERNAL_TESTS_FILTERS="test/deploy-tests-manifest.json,test/cache-components-tests-manifest.json" export NEXT_EXTERNAL_TESTS_FILTERS="test/deploy-tests-manifest.json,test/cache-components-tests-manifest.json"
export NEXT_E2E_TEST_TIMEOUT=240000 export NEXT_E2E_TEST_TIMEOUT=240000
export IS_TURBOPACK_TEST=1 export IS_TURBOPACK_TEST=1
......
...@@ -190,6 +190,7 @@ jobs: ...@@ -190,6 +190,7 @@ jobs:
NEXT_TEST_MODE=deploy \ NEXT_TEST_MODE=deploy \
IS_WEBPACK_TEST=1 \ IS_WEBPACK_TEST=1 \
NEXT_ENABLE_ADAPTER=0 \ NEXT_ENABLE_ADAPTER=0 \
NEXT_TEST_DEPLOY_TARGET_VERCEL=1 \
NEXT_EXTERNAL_TESTS_FILTERS="test/deploy-tests-manifest.json" \ NEXT_EXTERNAL_TESTS_FILTERS="test/deploy-tests-manifest.json" \
NEXT_TEST_VERSION="${{ needs.setup.outputs.next-version }}" \ NEXT_TEST_VERSION="${{ needs.setup.outputs.next-version }}" \
VERCEL_CLI_VERSION="${{ github.event.inputs.vercelCliVersion || 'vercel@latest' }}" \ VERCEL_CLI_VERSION="${{ github.event.inputs.vercelCliVersion || 'vercel@latest' }}" \
...@@ -240,6 +241,7 @@ jobs: ...@@ -240,6 +241,7 @@ jobs:
NEXT_TEST_MODE=deploy \ NEXT_TEST_MODE=deploy \
IS_TURBOPACK_TEST=1 \ IS_TURBOPACK_TEST=1 \
NEXT_ENABLE_ADAPTER=0 \ NEXT_ENABLE_ADAPTER=0 \
NEXT_TEST_DEPLOY_TARGET_VERCEL="${{ github.event.inputs.deployScriptPath == '' && '1' || '' }}" \
NEXT_TEST_CONTINUE_ON_ERROR="${{ github.event.inputs.continueOnError || false }}" \ NEXT_TEST_CONTINUE_ON_ERROR="${{ github.event.inputs.continueOnError || false }}" \
NEXT_EXTERNAL_TESTS_FILTERS="test/deploy-tests-manifest.json" \ NEXT_EXTERNAL_TESTS_FILTERS="test/deploy-tests-manifest.json" \
NEXT_TEST_VERSION="${{ needs.setup.outputs.next-version }}" \ NEXT_TEST_VERSION="${{ needs.setup.outputs.next-version }}" \
...@@ -292,6 +294,7 @@ jobs: ...@@ -292,6 +294,7 @@ jobs:
NEXT_TEST_MODE=deploy \ NEXT_TEST_MODE=deploy \
IS_TURBOPACK_TEST=1 \ IS_TURBOPACK_TEST=1 \
NEXT_ENABLE_ADAPTER=1 \ NEXT_ENABLE_ADAPTER=1 \
NEXT_TEST_DEPLOY_TARGET_VERCEL=1 \
NEXT_EXTERNAL_TESTS_FILTERS="test/deploy-tests-manifest.json" \ NEXT_EXTERNAL_TESTS_FILTERS="test/deploy-tests-manifest.json" \
NEXT_TEST_VERSION="${{ needs.setup.outputs.next-version }}" \ NEXT_TEST_VERSION="${{ needs.setup.outputs.next-version }}" \
VERCEL_CLI_VERSION="${{ github.event.inputs.vercelCliVersion || 'vercel@latest' }}" \ VERCEL_CLI_VERSION="${{ github.event.inputs.vercelCliVersion || 'vercel@latest' }}" \
......
...@@ -187,6 +187,14 @@ Set `NEXT_TEST_DEPLOY_URL` to run against an existing deployment instead of crea ...@@ -187,6 +187,14 @@ Set `NEXT_TEST_DEPLOY_URL` to run against an existing deployment instead of crea
NEXT_TEST_DEPLOY_URL=https://your-deployment.vercel.app pnpm test-deploy-turbo test/e2e/app-dir/actions/ NEXT_TEST_DEPLOY_URL=https://your-deployment.vercel.app pnpm test-deploy-turbo test/e2e/app-dir/actions/
``` ```
**Vercel-specific suites**
Suites gated on the `vercel` condition (`// @force-gate vercel`, see [`test/lib/gate/README.md`](../../test/lib/gate/README.md)) only run when the deploy is declared as Vercel. CI sets this on every Vercel deploy job; set it yourself when deploying to Vercel locally:
```sh
NEXT_TEST_DEPLOY_TARGET_VERCEL=1 pnpm test-deploy-turbo test/e2e/app-dir/actions/
```
## Integration testing outside the repository with local builds ## Integration testing outside the repository with local builds
You can locally generate builds for each package in this repository with: You can locally generate builds for each package in this repository with:
......
...@@ -49,6 +49,9 @@ describe('empty-generate-static-params', () => { ...@@ -49,6 +49,9 @@ describe('empty-generate-static-params', () => {
`) `)
}) })
} else { } else {
// The Turbopack deploy snapshot matches Vercel's build logs, which omit
// leading indentation. Other hosts format their build logs differently.
// @force-gate !deploy || vercel
describe('literal empty array', () => { describe('literal empty array', () => {
const { next, isTurbopack, isNextDeploy } = nextTestSetup({ const { next, isTurbopack, isNextDeploy } = nextTestSetup({
files: __dirname, files: __dirname,
...@@ -130,6 +133,9 @@ describe('empty-generate-static-params', () => { ...@@ -130,6 +133,9 @@ describe('empty-generate-static-params', () => {
}, 240_000) }, 240_000)
}) })
// The Turbopack deploy snapshot matches Vercel's build logs, which omit
// leading indentation. Other hosts format their build logs differently.
// @force-gate !deploy || vercel
describe('computed empty array', () => { describe('computed empty array', () => {
const { next, isTurbopack, isNextDeploy } = nextTestSetup({ const { next, isTurbopack, isNextDeploy } = nextTestSetup({
files: __dirname, files: __dirname,
......
...@@ -82,6 +82,10 @@ describe('non-root-project-monorepo', () => { ...@@ -82,6 +82,10 @@ describe('non-root-project-monorepo', () => {
}) })
}) })
// Deployed server bundles embed the build machine's source path, and
// `sourceFileUrl()` hardcodes it as Vercel's build directory
// (`/vercel/path0`). Other hosts build in a different directory.
// @force-gate !deploy || vercel
describe('import.meta.url', () => { describe('import.meta.url', () => {
it('should work during RSC', async () => { it('should work during RSC', async () => {
const $ = await next.render$('/import-meta-url-rsc') const $ = await next.render$('/import-meta-url-rsc')
......
...@@ -7,6 +7,10 @@ describe('proxy-runtime', () => { ...@@ -7,6 +7,10 @@ describe('proxy-runtime', () => {
skipStart: true, skipStart: true,
}) })
// `getBuildError()` stops capturing at Vercel's
// `Error: Command "..." exited with N` line. Other hosts don't print it, so
// anything they log after the build error would end up in the snapshot.
// @force-gate !deploy || vercel
it('should error when proxy file has runtime config export', async () => { it('should error when proxy file has runtime config export', async () => {
let cliOutput: string let cliOutput: string
......
...@@ -9,6 +9,11 @@ describe('use-cache-segment-configs', () => { ...@@ -9,6 +9,11 @@ describe('use-cache-segment-configs', () => {
skipStart: process.env.NEXT_TEST_MODE !== 'dev', skipStart: process.env.NEXT_TEST_MODE !== 'dev',
}) })
// The deploy snapshots match Vercel's build-log format, which drops
// code-frame indentation, and `getBuildOutput()` stops at Vercel's
// `Error: Command "..." exited with N` line. Other hosts format their build
// logs differently.
// @force-gate !deploy || vercel
it("it should error when using segment configs that aren't supported by useCache", async () => { it("it should error when using segment configs that aren't supported by useCache", async () => {
if (isNextDev) { if (isNextDev) {
const browser = await next.browser('/runtime') const browser = await next.browser('/runtime')
......
...@@ -3,6 +3,11 @@ import { nextTestSetup } from 'e2e-utils' ...@@ -3,6 +3,11 @@ import { nextTestSetup } from 'e2e-utils'
// pnpm installs file: dependencies inside node_modules. npm would link them to // pnpm installs file: dependencies inside node_modules. npm would link them to
// fixture source, which is transpiled without transpilePackages. // fixture source, which is transpiled without transpilePackages.
describe('transpile-packages-typescript-foreign', () => { describe('transpile-packages-typescript-foreign', () => {
// The build only fails because Vercel reads vercel.json's
// `installCommand: "pnpm install"`, which copies the `file:` package into
// node_modules. A host that ignores vercel.json may link it instead, and
// the build would then succeed.
// @force-gate !deploy || vercel
describe('without transpilePackages', () => { describe('without transpilePackages', () => {
const { next, isNextDev } = nextTestSetup({ const { next, isNextDev } = nextTestSetup({
files: __dirname, files: __dirname,
......
...@@ -85,9 +85,18 @@ There are two tiers: ...@@ -85,9 +85,18 @@ There are two tiers:
- **static** — the run's own shape (`dev`, `start`, `deploy`, `mode`, - **static** — the run's own shape (`dev`, `start`, `deploy`, `mode`,
`turbopack`, `rspack`, `webpack`, `bundler`, `react18`, `wasm`, `linux`, `turbopack`, `rspack`, `webpack`, `bundler`, `react18`, `wasm`, `linux`,
`macos`, `windows`, `ci`), semantic aliases for `!dev` that state the reason `macos`, `windows`, `ci`), semantic aliases for `!dev` that state the reason
rather than the mode (`prod`, `prefetching`), specialized CI variants rather than the mode (`prod`, `prefetching`), the deploy host (`vercel`: a
deploy run declared as Vercel with `NEXT_TEST_DEPLOY_TARGET_VERCEL=1`, as
opposed to another host that deploys through `NEXT_TEST_DEPLOY_SCRIPT_PATH`
to test its adapter), specialized CI variants
(`adapter`, `nodeMiddleware`, `standaloneOutput`, `turbopackDev`, (`adapter`, `nodeMiddleware`, `standaloneOutput`, `turbopackDev`,
`turbopackBuild`), plus `FIXME` / `TODO`, which are always false. `turbopackBuild`), plus `FIXME` / `TODO`, which are always false.
Gate on `vercel` rather than `deploy` when the reason is specific to Vercel
(its payload limit, image CDN, `x-vercel-*` headers), so other platforms
still run the suite: `@force-gate vercel` for a Vercel-only suite,
`@force-gate !deploy || vercel` to skip only other platforms, `!vercel` to
skip only Vercel.
- **lazy** — a predicate over the fixture's *resolved* `next.config` - **lazy** — a predicate over the fixture's *resolved* `next.config`
(`cacheComponents`, `ppr`, `prefetchInlining`, `output`, …), read the first (`cacheComponents`, `ppr`, `prefetchInlining`, `output`, …), read the first
time a gate asks for it. time a gate asks for it.
......
...@@ -95,6 +95,19 @@ export const conditions: Record<string, Condition> = { ...@@ -95,6 +95,19 @@ export const conditions: Record<string, Condition> = {
'running against a real deployment', 'running against a real deployment',
() => getGateTestContext().mode === 'deploy' () => getGateTestContext().mode === 'deploy'
), ),
// Other hosts run the deploy suites through custom scripts to validate their
// adapters, so gate on `vercel` rather than `deploy` when the reason is
// specific to Vercel: `@force-gate vercel` for a Vercel-only suite,
// `@force-gate !deploy || vercel` to skip only other hosts, `!vercel` to
// skip only Vercel. The host is declared, not inferred: our CI sets
// `NEXT_TEST_DEPLOY_TARGET_VERCEL=1` on every job that deploys to Vercel.
vercel: staticCondition(
'running against a Vercel deployment (`NEXT_TEST_DEPLOY_TARGET_VERCEL=1`); ' +
'false outside deploy mode',
() =>
getGateTestContext().mode === 'deploy' &&
process.env.NEXT_TEST_DEPLOY_TARGET_VERCEL === '1'
),
// Semantic aliases for `!dev`. A gate is a claim about *why* a suite cannot // Semantic aliases for `!dev`. A gate is a claim about *why* a suite cannot
// run, so prefer the name that states the reason over the bare mode check. // run, so prefer the name that states the reason over the bare mode check.
......
...@@ -309,6 +309,55 @@ describe('@gate runtime', () => { ...@@ -309,6 +309,55 @@ describe('@gate runtime', () => {
} }
}) })
it('runs `vercel` only for a deploy declared as Vercel', async () => {
const original = process.env.NEXT_TEST_DEPLOY_TARGET_VERCEL
const vercelOnly = parseGate('vercel', true)
const notOtherHosts = parseGate('!deploy || vercel', true)
const results: [string, string, string][] = []
try {
for (const [mode, target] of [
['deploy', '1'],
['deploy', undefined],
['deploy', '0'],
['start', '1'],
['start', undefined],
] as const) {
if (target === undefined) {
delete process.env.NEXT_TEST_DEPLOY_TARGET_VERCEL
} else {
process.env.NEXT_TEST_DEPLOY_TARGET_VERCEL = target
}
setGateTestContext({
mode,
bundler: 'turbopack',
react18: false,
wasm: false,
})
results.push([
`${mode}, ${target ?? 'unset'}`,
(await __testing.decideGates([vercelOnly])).type,
(await __testing.decideGates([notOtherHosts])).type,
])
}
} finally {
if (original === undefined) {
delete process.env.NEXT_TEST_DEPLOY_TARGET_VERCEL
} else {
process.env.NEXT_TEST_DEPLOY_TARGET_VERCEL = original
}
}
// [mode + NEXT_TEST_DEPLOY_TARGET_VERCEL, `@force-gate vercel`, `@force-gate !deploy || vercel`]
expect(results).toEqual([
['deploy, 1', 'run', 'run'],
['deploy, unset', 'force-pass', 'force-pass'],
['deploy, 0', 'force-pass', 'force-pass'],
['start, 1', 'force-pass', 'run'],
['start, unset', 'force-pass', 'run'],
])
})
it('skips the test for real when the condition is false', () => { it('skips the test for real when the condition is false', () => {
const body = () => {} const body = () => {}
const fakes = withFakeTestGlobals(() => { const fakes = withFakeTestGlobals(() => {
......
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