Unverified Commit 1a183ebd authored by Jamiboy Mohammad's avatar Jamiboy Mohammad Committed by GitHub

test: enable deployment coverage for monorepo fixtures (#99395)

## Summary

Enable deployment coverage for `import-meta-glob-monorepo` and
`non-root-project-monorepo`. Both apps build under `apps/web`, so
configure Vercel's output directory accordingly and enable Corepack to
use the declared pnpm version for workspace installation and builds.

Match `import.meta.url` against the exact source-file URL for the build
environment, retaining the filename and percent-encoding assertions and
Windows Turbopack path canonicalization.

This is the third layer of the deployment test flag stack, based on
#99534 (which depends on #99533). Both nested configs are prepared with
`patchFileWithDeployEnvAssignments()`, which wraps `PatchedFileRef`,
checks the resolved harness mode, and uses the shared
`getDeploymentTestEnvAssignments()` helper. They capture the same static
experimental flag list as the root harness, including partial
prefetching. Source configs stay free of deployment aliases. Automatic
nested-config discovery remains outside this stack.

Dependency versions, assertions, and unrelated bundler/dev-mode
restrictions are preserved. #99407 is not part of this stack.

## Verification

- Full bootstrap: 18/18 tasks passed. Repository TypeScript checking,
formatting, and ESLint passed.
- Shared helper and existing deployment lifecycle unit tests: 41/41
passed, covering enabled/disabled values, missing and empty values,
escaping, and capture timing.
- Focused local production Turbopack tests: 11/11 passed across both
monorepo suites.
- Real Vercel deployments against `16.4.0-canary.55`: the larger
monorepo suite passed 10/10 assertions with flags unset and 10/10 with
Cache Components, partial prefetching, and cached navigations enabled.
Enabled remote logs confirmed Cache Components and cached navigations.
- The glob suite passed its assertion in both normal and enabled modes
on targeted retries. Both monorepo suites therefore passed 11/11
assertions per mode across four successful real deployments. The enabled
glob build also reported Cache Components and cached navigations.
Initial glob attempts failed before assertions due to Vercel transport
errors during project linking and CLI installation; no test changes were
made for the retries.

### Follow-up helper validation

- `patchFileWithDeployEnvAssignments()` now appends captured assignments
after a newline in deploy mode, matching the root harness. Dev/start
modes preserve the file content unchanged.
- 41/41 unit tests, 11/11 local production assertions, and the glob
suite's dev assertion passed. Full bootstrap (18/18), TypeScript,
formatting, and ESLint passed.
- A fresh feature-enabled deployment of the larger monorepo suite
installed and enabled the feature flags, but passed 8/10 assertions: the
two encoded server source URLs used `/var/task/` instead of the asserted
`/vercel/path0/`. Assertions are preserved; this deployment is not
recorded as a suite pass. The feature-enabled glob deployment passed its
assertion. Overall deploy result: 9 passed, 2 failed.

- Append-placement follow-up: 10 standalone VM behavior checks passed
using the actual helper, mode declaration, and assignment generator,
including dev/start preservation and deploy files ending without a
newline or with a line comment. The 41 unit tests, full bootstrap
(18/18), repository TypeScript, formatting, and ESLint also passed.
Deployment tests were not rerun for this placement change; the
source-URL failures above remain unresolved.

<!-- NEXT_JS_LLM -->
parent 9dd33e01
import { nextTestSetup, FileRef } from 'e2e-utils' import {
nextTestSetup,
FileRef,
patchFileWithDeployEnvAssignments,
} from 'e2e-utils'
import * as path from 'path' import * as path from 'path'
// `import.meta.glob` is a Turbopack-only feature, and webpack compiles // `import.meta.glob` is a Turbopack-only feature, and webpack compiles
...@@ -12,27 +16,29 @@ const testFn = ...@@ -12,27 +16,29 @@ const testFn =
: describe : describe
testFn('import-meta-glob-monorepo', () => { testFn('import-meta-glob-monorepo', () => {
const { next, skipped } = nextTestSetup({ const { next } = nextTestSetup({
files: { files: {
apps: new FileRef(path.resolve(__dirname, 'apps')), apps: new FileRef(path.resolve(__dirname, 'apps')),
// Deliberately shadows apps/web/content, to pin down which one a // Deliberately shadows apps/web/content, to pin down which one a
// `/`-rooted pattern resolves from. // `/`-rooted pattern resolves from.
content: new FileRef(path.resolve(__dirname, 'content')), content: new FileRef(path.resolve(__dirname, 'content')),
'vercel.json': new FileRef(path.resolve(__dirname, 'vercel.json')),
'pnpm-workspace.yaml': `packages: 'pnpm-workspace.yaml': `packages:
- 'apps/*' - 'apps/*'
`, `,
}, },
overrideFiles: {
'apps/web/next.config.js': patchFileWithDeployEnvAssignments(
path.join(__dirname, 'apps/web/next.config.js')
),
},
packageJson: require('./package.json'), packageJson: require('./package.json'),
buildCommand: 'pnpm build', buildCommand: 'pnpm build',
startCommand: (global as any).isNextDev ? 'pnpm dev' : 'pnpm start', startCommand: (global as any).isNextDev ? 'pnpm dev' : 'pnpm start',
installCommand: 'pnpm i', installCommand: 'pnpm i',
skipDeployment: true, env: { ENABLE_EXPERIMENTAL_COREPACK: '1' },
}) })
if (skipped) {
return
}
it('should resolve a `/`-rooted pattern from the project directory, like a plain import', async () => { it('should resolve a `/`-rooted pattern from the project directory, like a plain import', async () => {
const $ = await next.render$('/glob') const $ = await next.render$('/glob')
// The point of the test: a glob and a plain import agree about what `/` means. // The point of the test: a glob and a plain import agree about what `/` means.
......
{
"outputDirectory": "apps/web/.next"
}
import { nextTestSetup, FileRef } from 'e2e-utils' import {
nextTestSetup,
FileRef,
patchFileWithDeployEnvAssignments,
isNextDeploy,
} from 'e2e-utils'
import { import {
waitForRedbox, waitForRedbox,
waitForNoRedbox, waitForNoRedbox,
...@@ -6,10 +11,9 @@ import { ...@@ -6,10 +11,9 @@ import {
getRedboxSource, getRedboxSource,
} from 'next-test-utils' } from 'next-test-utils'
import * as path from 'path' import * as path from 'path'
import { realpathSync } from 'fs'
import { pathToFileURL } from 'url'
// TODO(deploy-test-completion): Re-enable this suite in deploy mode.
// It likely controls the local Next.js build or server lifecycle.
// @force-gate !deploy
describe('non-root-project-monorepo', () => { describe('non-root-project-monorepo', () => {
const { next, isTurbopack, isNextDev, isRspack } = nextTestSetup({ const { next, isTurbopack, isNextDev, isRspack } = nextTestSetup({
files: { files: {
...@@ -18,17 +22,38 @@ describe('non-root-project-monorepo', () => { ...@@ -18,17 +22,38 @@ describe('non-root-project-monorepo', () => {
// Deliberately shadows apps/web/content, to pin down which one a // Deliberately shadows apps/web/content, to pin down which one a
// `/`-rooted import resolves from. // `/`-rooted import resolves from.
content: new FileRef(path.resolve(__dirname, 'content')), content: new FileRef(path.resolve(__dirname, 'content')),
'vercel.json': new FileRef(path.resolve(__dirname, 'vercel.json')),
'pnpm-workspace.yaml': `packages: 'pnpm-workspace.yaml': `packages:
- 'apps/*' - 'apps/*'
- 'packages/*' - 'packages/*'
`, `,
}, },
overrideFiles: {
'apps/web/next.config.js': patchFileWithDeployEnvAssignments(
path.join(__dirname, 'apps/web/next.config.js')
),
},
packageJson: require('./package.json'), packageJson: require('./package.json'),
buildCommand: 'pnpm build', buildCommand: 'pnpm build',
startCommand: (global as any).isNextDev ? 'pnpm dev' : 'pnpm start', startCommand: (global as any).isNextDev ? 'pnpm dev' : 'pnpm start',
installCommand: 'pnpm i', installCommand: 'pnpm i',
env: { ENABLE_EXPERIMENTAL_COREPACK: '1' },
}) })
function sourceFileUrl(file: string) {
// Server bundles preserve the source path from the build environment.
if (isNextDeploy) {
return new URL(file, 'file:///vercel/path0/apps/web/').href
}
// Turbopack expands Windows 8.3 names (e.g. RUNNER~1) in source paths.
const testDir =
process.platform === 'win32' && isTurbopack
? realpathSync.native(next.testDir)
: realpathSync(next.testDir)
const filePath = path.join(testDir, 'apps/web', file)
return pathToFileURL(filePath).href
}
describe('server relative import', () => { describe('server relative import', () => {
it('should resolve a `/`-rooted import from the project directory, not the workspace root', async () => { it('should resolve a `/`-rooted import from the project directory, not the workspace root', async () => {
// `/content/where` exists both in apps/web (the project directory) and at // `/content/where` exists both in apps/web (the project directory) and at
...@@ -61,15 +86,15 @@ describe('non-root-project-monorepo', () => { ...@@ -61,15 +86,15 @@ describe('non-root-project-monorepo', () => {
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')
expect($('p').text()).toMatch( expect($('p').text()).toBe(
/^file:\/\/.*\/next-install-[^/]+\/apps\/web\/app\/import-meta-url-rsc\/page.tsx$/ sourceFileUrl('app/import-meta-url-rsc/page.tsx')
) )
}) })
it('should work during SSR', async () => { it('should work during SSR', async () => {
const $ = await next.render$('/import-meta-url-ssr') const $ = await next.render$('/import-meta-url-ssr')
expect($('p').text()).toMatch( expect($('p').text()).toBe(
/^file:\/\/.*\/next-install-[^/]+\/apps\/web\/app\/import-meta-url-ssr\/page.tsx$/ sourceFileUrl('app/import-meta-url-ssr/page.tsx')
) )
}) })
...@@ -82,8 +107,8 @@ describe('non-root-project-monorepo', () => { ...@@ -82,8 +107,8 @@ describe('non-root-project-monorepo', () => {
'file:///ROOT/apps/web/app/import-meta-url-ssr/page.tsx' 'file:///ROOT/apps/web/app/import-meta-url-ssr/page.tsx'
) )
} else { } else {
expect(await browser.elementByCss('p').text()).toMatch( expect(await browser.elementByCss('p').text()).toBe(
/^file:\/\/.*\/next-install-[^/]+\/apps\/web\/app\/import-meta-url-ssr\/page.tsx$/ sourceFileUrl('app/import-meta-url-ssr/page.tsx')
) )
} }
await browser.close() await browser.close()
...@@ -94,15 +119,15 @@ describe('non-root-project-monorepo', () => { ...@@ -94,15 +119,15 @@ describe('non-root-project-monorepo', () => {
describe('non-url-safe characters', () => { describe('non-url-safe characters', () => {
it('should encode special chars during RSC', async () => { it('should encode special chars during RSC', async () => {
const $ = await next.render$('/import-meta-url-encoded-rsc') const $ = await next.render$('/import-meta-url-encoded-rsc')
expect($('p').text()).toMatch( expect($('p').text()).toBe(
/^file:\/\/.*\/next-install-[^/]+\/apps\/web\/app\/import-meta-url-encoded-rsc\/with%20space.ts$/ sourceFileUrl('app/import-meta-url-encoded-rsc/with space.ts')
) )
}) })
it('should encode special chars during SSR', async () => { it('should encode special chars during SSR', async () => {
const $ = await next.render$('/import-meta-url-encoded-ssr') const $ = await next.render$('/import-meta-url-encoded-ssr')
expect($('p').text()).toMatch( expect($('p').text()).toBe(
/^file:\/\/.*\/next-install-[^/]+\/apps\/web\/app\/import-meta-url-encoded-ssr\/with%20space.ts$/ sourceFileUrl('app/import-meta-url-encoded-ssr/with space.ts')
) )
}) })
...@@ -115,8 +140,8 @@ describe('non-root-project-monorepo', () => { ...@@ -115,8 +140,8 @@ describe('non-root-project-monorepo', () => {
'file:///ROOT/apps/web/app/import-meta-url-encoded-ssr/with%20space.ts' 'file:///ROOT/apps/web/app/import-meta-url-encoded-ssr/with%20space.ts'
) )
} else { } else {
expect(await browser.elementByCss('p').text()).toMatch( expect(await browser.elementByCss('p').text()).toBe(
/^file:\/\/.*\/next-install-[^/]+\/apps\/web\/app\/import-meta-url-encoded-ssr\/with%20space.ts$/ sourceFileUrl('app/import-meta-url-encoded-ssr/with space.ts')
) )
} }
await browser.close() await browser.close()
......
{
"outputDirectory": "apps/web/.next"
}
import { getDeploymentTestEnvAssignments } from './deployment-test-env'
import path from 'path' import path from 'path'
import assert from 'assert' import assert from 'assert'
import { flushAllTraces, setGlobal, trace } from 'next/dist/trace' import { flushAllTraces, setGlobal, trace } from 'next/dist/trace'
...@@ -233,6 +234,24 @@ export class PatchedFileRef { ...@@ -233,6 +234,24 @@ export class PatchedFileRef {
} }
} }
/**
* Return a PatchedFileRef that appends captured test env assignments when the
* harness copies the file in deploy mode. Other modes copy the content unchanged.
* Nested app configs need this because the deploy harness only patches the
* fixture-root config.
*
* TODO: Patch nested configs automatically in the deploy harness so fixtures no
* longer need these explicit overrides.
* https://github.com/vercel/next.js/blob/3854a98484ec2ce5bafcb074ef0fbad5290dede2/test/lib/next-modes/base.ts#L520-L554
*/
export function patchFileWithDeployEnvAssignments(
path: string
): PatchedFileRef {
return new PatchedFileRef(path, (content) =>
isNextDeploy ? `${content}\n` + getDeploymentTestEnvAssignments() : content
)
}
let nextInstance: NextInstance | undefined = undefined let nextInstance: NextInstance | undefined = undefined
if (typeof afterAll === 'function') { if (typeof afterAll === 'function') {
......
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