Unverified Commit 9dd33e01 authored by Jamiboy Mohammad's avatar Jamiboy Mohammad Committed by GitHub

test: capture deployment experimental flags in config (#99534)

## Summary

Capture the partial-prefetching and cached-navigation test flags in
deployed configs through the shared helper introduced in #99533,
matching Cache Components. The helper owns the static list of
experimental flags; the deploy harness no longer sends or translates the
corresponding `NEXT_PRIVATE_EXPERIMENTAL_*` aliases. The fixed
`NEXT_PRIVATE_TEST_MODE=e2e` mode setup is retained.

This is the second layer of the stack. The monorepo fixtures in #99395
will use the same helper for their copied nested configs.

## Verification

- Executed generated assignments for all three flags, covering
enabled/disabled values, omitted values, string escaping, and capture
timing. Together with the existing deployment lifecycle suite: 41/41
unit tests passed.
- Real Vercel deployments of
`test/e2e/app-dir/hello-world/hello-world.test.ts` against
`16.4.0-canary.55`: 4/4 assertions passed with flags unset and 4/4 with
all three flags enabled. The enabled build explicitly reported Cache
Components and cached navigations enabled.
- Full bootstrap (18/18 tasks), formatting, and ESLint passed.

<!-- NEXT_JS_LLM -->
parent dfb6e044
const deploymentTestFlags = ['__NEXT_CACHE_COMPONENTS']
const deploymentTestFlags = [
'__NEXT_CACHE_COMPONENTS',
'__NEXT_PARTIAL_PREFETCHING',
'__NEXT_EXPERIMENTAL_CACHED_NAVIGATIONS',
]
/**
* Capture test flags in the deployed config because Vercel environment variable
......
......@@ -546,14 +546,6 @@ export class NextInstance {
if (process.env.NEXT_PRIVATE_TEST_MODE) {
process.env.__NEXT_TEST_MODE = process.env.NEXT_PRIVATE_TEST_MODE
}
// alias experimental feature flags for deployment compatibility
if (process.env.NEXT_PRIVATE_EXPERIMENTAL_PARTIAL_PREFETCHING) {
process.env.__NEXT_PARTIAL_PREFETCHING = process.env.NEXT_PRIVATE_EXPERIMENTAL_PARTIAL_PREFETCHING
}
if (process.env.NEXT_PRIVATE_EXPERIMENTAL_CACHED_NAVIGATIONS) {
process.env.__NEXT_EXPERIMENTAL_CACHED_NAVIGATIONS = process.env.NEXT_PRIVATE_EXPERIMENTAL_CACHED_NAVIGATIONS
}
`
)
......
......@@ -493,18 +493,6 @@ export class NextDeployInstance extends NextInstance {
)
}
// Add experimental feature flags
if (process.env.__NEXT_PARTIAL_PREFETCHING) {
additionalEnv.push(
`NEXT_PRIVATE_EXPERIMENTAL_PARTIAL_PREFETCHING=${process.env.__NEXT_PARTIAL_PREFETCHING}`
)
}
if (process.env.__NEXT_EXPERIMENTAL_CACHED_NAVIGATIONS) {
additionalEnv.push(
`NEXT_PRIVATE_EXPERIMENTAL_CACHED_NAVIGATIONS=${process.env.__NEXT_EXPERIMENTAL_CACHED_NAVIGATIONS}`
)
}
if (process.env.IS_TURBOPACK_TEST) {
additionalEnv.push(`IS_TURBOPACK_TEST=1`)
}
......
import { runInNewContext } from 'vm'
import { getDeploymentTestEnvAssignments } from '../../lib/e2e-utils/deployment-test-env'
describe.each(['__NEXT_CACHE_COMPONENTS'])(
'deployment capture of %s',
(flag) => {
beforeEach(() => {
jest.replaceProperty(process, 'env', {
...process.env,
__NEXT_CACHE_COMPONENTS: '',
})
describe.each([
'__NEXT_CACHE_COMPONENTS',
'__NEXT_PARTIAL_PREFETCHING',
'__NEXT_EXPERIMENTAL_CACHED_NAVIGATIONS',
])('deployment capture of %s', (flag) => {
beforeEach(() => {
jest.replaceProperty(process, 'env', {
...process.env,
__NEXT_CACHE_COMPONENTS: '',
__NEXT_PARTIAL_PREFETCHING: '',
__NEXT_EXPERIMENTAL_CACHED_NAVIGATIONS: '',
})
})
afterEach(() => {
jest.restoreAllMocks()
})
afterEach(() => {
jest.restoreAllMocks()
})
it.each(['true', 'false', '0', '"; process.env.INJECTED = "yes"; //\n\\'])(
'restores the literal value %j in the deployed process',
(value) => {
process.env[flag] = value
const env: Record<string, string> = {}
it.each(['true', 'false', '0', '"; process.env.INJECTED = "yes"; //\n\\'])(
'restores the literal value %j in the deployed process',
(value) => {
process.env[flag] = value
const env: Record<string, string> = {}
runInNewContext(getDeploymentTestEnvAssignments(), { process: { env } })
runInNewContext(getDeploymentTestEnvAssignments(), { process: { env } })
expect(env).toEqual({ [flag]: value })
}
)
expect(env).toEqual({ [flag]: value })
}
)
it.each(['', undefined])(
'leaves the deployed environment unchanged when the local flag is %j',
(value) => {
if (value === undefined) delete process.env[flag]
else process.env[flag] = value
const env = { [flag]: 'deployment-value' }
it.each(['', undefined])(
'leaves the deployed environment unchanged when the local flag is %j',
(value) => {
if (value === undefined) delete process.env[flag]
else process.env[flag] = value
const env = { [flag]: 'deployment-value' }
runInNewContext(getDeploymentTestEnvAssignments(), { process: { env } })
runInNewContext(getDeploymentTestEnvAssignments(), { process: { env } })
expect(env).toEqual({ [flag]: 'deployment-value' })
}
)
expect(env).toEqual({ [flag]: 'deployment-value' })
}
)
it('captures the value when generating the config, without needing a remote alias', () => {
process.env[flag] = 'true'
const assignments = getDeploymentTestEnvAssignments()
process.env[flag] = 'false'
const env: Record<string, string> = {}
it('captures the value when generating the config, without needing a remote alias', () => {
process.env[flag] = 'true'
const assignments = getDeploymentTestEnvAssignments()
process.env[flag] = 'false'
const env: Record<string, string> = {}
runInNewContext(assignments, { process: { env } })
runInNewContext(assignments, { process: { env } })
expect(env[flag]).toBe('true')
})
}
)
expect(env[flag]).toBe('true')
})
})
it('does not copy unrelated environment variables into the config', () => {
jest.replaceProperty(process, 'env', {
......
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