Unverified Commit 7f3821a9 authored by Jamiboy Mohammad's avatar Jamiboy Mohammad Committed by GitHub

test: migrate and explain custom server deploy exclusions (#98994)

## Summary

Custom-server suites depend on local server entrypoints that deploy mode
does not launch. Replace their legacy `skipDeployment` exclusions and
`skipped` returns with `@force-gate !deploy` and explain the dependency,
while preserving their existing local mode restrictions and assertions.

This covers six test files, including the custom-server sections of API
body parsing and OpenTelemetry. The ordinary API JSON body-parser case
remains enabled in deploy mode; only the Express pre-parsing cases are
excluded. The custom-server shutdown suite also requires the runner to
signal its server process and observe `after()` completion.

Stack: #99012 → #98994 → #99392 → #98911. Based on #99012; #99392
separately explains local process-control exclusions.

## Verification

- The two added suites passed in both webpack development and production
modes: five tests in each mode.
- Collection with the real gate runtime and fixture setup stubbed
confirmed all five tests enabled locally, and only the ordinary API
body-parser test enabled in deploy mode. Both parameterized shutdown
signals are excluded in deploy.
- All 24 gate-transform tests passed. Formatting and ESLint passed for
the added files.
- The JavaScript workspace build passed. The full bootstrap build failed
in the native Rust step (`cargo metadata failed to run`).
- No new deployment was created. The ordinary API body-parser case
passed in the earlier deployment experiment.

<!-- NEXT_JS_LLM -->
parent 71de7e6a
...@@ -2,12 +2,9 @@ import { nextTestSetup } from 'e2e-utils' ...@@ -2,12 +2,9 @@ import { nextTestSetup } from 'e2e-utils'
describe('API body parser', () => { describe('API body parser', () => {
describe('without custom server', () => { describe('without custom server', () => {
const { next, skipped } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
// Uses a custom HTTP/proxy server in front of Next.js; not applicable in deploy mode.
skipDeployment: true,
}) })
if (skipped) return
it('should parse JSON body', async () => { it('should parse JSON body', async () => {
const res = await next.fetch('/api', { const res = await next.fetch('/api', {
...@@ -22,8 +19,11 @@ describe('API body parser', () => { ...@@ -22,8 +19,11 @@ describe('API body parser', () => {
}) })
}) })
// Deploy mode does not run server.js, whose Express middleware parses the body
// before passing the request to Next.js.
// @force-gate !deploy
describe('with custom server (pre-parsed body)', () => { describe('with custom server (pre-parsed body)', () => {
const { next, skipped } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
startCommand: 'node server.js', startCommand: 'node server.js',
serverReadyPattern: /- Local:/, serverReadyPattern: /- Local:/,
...@@ -31,10 +31,7 @@ describe('API body parser', () => { ...@@ -31,10 +31,7 @@ describe('API body parser', () => {
dependencies: { dependencies: {
express: '4', express: '4',
}, },
// Uses a custom HTTP/proxy server in front of Next.js; not applicable in deploy mode.
skipDeployment: true,
}) })
if (skipped) return
it('should not throw if request body is already parsed in custom middleware', async () => { it('should not throw if request body is already parsed in custom middleware', async () => {
const res = await next.fetch('/api', { const res = await next.fetch('/api', {
......
...@@ -2,10 +2,12 @@ import { nextTestSetup } from 'e2e-utils' ...@@ -2,10 +2,12 @@ import { nextTestSetup } from 'e2e-utils'
import { check, retry } from 'next-test-utils' import { check, retry } from 'next-test-utils'
import { join } from 'path' import { join } from 'path'
// These tests start a custom Next.js server (server.js),
// which is not supported in deploy mode.
// @force-gate !deploy
describe('custom-app-server-action-redirect', () => { describe('custom-app-server-action-redirect', () => {
const { next, skipped } = nextTestSetup({ const { next } = nextTestSetup({
files: join(__dirname, 'custom-server'), files: join(__dirname, 'custom-server'),
skipDeployment: true,
startCommand: 'node server.js', startCommand: 'node server.js',
serverReadyPattern: /Next mode: (production|development)/, serverReadyPattern: /Next mode: (production|development)/,
dependencies: { dependencies: {
...@@ -13,10 +15,6 @@ describe('custom-app-server-action-redirect', () => { ...@@ -13,10 +15,6 @@ describe('custom-app-server-action-redirect', () => {
}, },
}) })
if (skipped) {
return
}
it('redirects with basepath properly when server action handler uses `redirect`', async () => { it('redirects with basepath properly when server action handler uses `redirect`', async () => {
const browser = await next.browser('/base') const browser = await next.browser('/base')
const getCount = async () => browser.elementByCss('#current-count').text() const getCount = async () => browser.elementByCss('#current-count').text()
......
import { isNextDev, nextTestSetup } from 'e2e-utils' import { isNextDev, nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils' import { retry } from 'next-test-utils'
// These tests send SIGINT/SIGTERM to server.mjs and check that after() finishes.
// Deploy mode does not launch this custom server or give the test runner control
// over the deployed process's shutdown.
// @force-gate !deploy
describe('after during server shutdown - custom server', () => { describe('after during server shutdown - custom server', () => {
const { next, skipped } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
startCommand: 'node server.mjs', startCommand: 'node server.mjs',
serverReadyPattern: /Custom server started/, serverReadyPattern: /Custom server started/,
forcedPort: 'random', forcedPort: 'random',
skipStart: true, skipStart: true,
skipDeployment: true, // the tests use cli logs and a custom server
env: { env: {
NODE_ENV: isNextDev ? 'development' : 'production', NODE_ENV: isNextDev ? 'development' : 'production',
DEBUG: '1', DEBUG: '1',
}, },
}) })
if (skipped) {
return
}
beforeEach(async () => { beforeEach(async () => {
await next.start() await next.start()
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils' import { retry } from 'next-test-utils'
// These tests start a custom Next.js server (server.js),
// which is not supported in deploy mode.
// @force-gate !deploy
describe('custom-app-render', () => { describe('custom-app-render', () => {
const { next, skipped } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
skipDeployment: true,
startCommand: 'node server.js', startCommand: 'node server.js',
serverReadyPattern: /Next mode: (production|development)/, serverReadyPattern: /Next mode: (production|development)/,
dependencies: { dependencies: {
...@@ -12,10 +14,6 @@ describe('custom-app-render', () => { ...@@ -12,10 +14,6 @@ describe('custom-app-render', () => {
}, },
}) })
if (skipped) {
return
}
it.each(['/', '/render'])('should render %s', async (page) => { it.each(['/', '/render'])('should render %s', async (page) => {
const $ = await next.render$(page) const $ = await next.render$(page)
expect($('#page').data('page')).toBe(page) expect($('#page').data('page')).toBe(page)
......
...@@ -19,17 +19,18 @@ describe.each([ ...@@ -19,17 +19,18 @@ describe.each([
const tlsOpts = const tlsOpts =
useHttps === 'true' ? { rejectUnauthorized: false } : undefined useHttps === 'true' ? { rejectUnauthorized: false } : undefined
// These tests start a custom Next.js server (server.js),
// which is not supported in deploy mode.
// @force-gate !deploy
describe('with dynamic assetPrefix', () => { describe('with dynamic assetPrefix', () => {
const { next, skipped } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
startCommand: 'node server.js', startCommand: 'node server.js',
serverReadyPattern: /- Local:/, serverReadyPattern: /- Local:/,
env: { USE_HTTPS: useHttps, NODE_ENV: sharedNodeEnv }, env: { USE_HTTPS: useHttps, NODE_ENV: sharedNodeEnv },
dependencies: sharedDeps, dependencies: sharedDeps,
skipDeployment: true,
disableAutoSkewProtection: true, disableAutoSkewProtection: true,
}) })
if (skipped) return
it('should render the custom 404 page for an unmatched request', async () => { it('should render the custom 404 page for an unmatched request', async () => {
const response = await fetchViaRawHttp( const response = await fetchViaRawHttp(
...@@ -155,8 +156,12 @@ describe.each([ ...@@ -155,8 +156,12 @@ describe.each([
) )
}) })
}) })
;(isNextDev ? describe.skip : describe)('with generateEtags enabled', () => { // These tests start a custom Next.js server (server.js),
const { next, skipped } = nextTestSetup({ // which is not supported in deploy mode.
// @force-gate !deploy
// @force-gate !dev
describe('with generateEtags enabled', () => {
const { next } = nextTestSetup({
files: __dirname, files: __dirname,
startCommand: 'node server.js', startCommand: 'node server.js',
serverReadyPattern: /- Local:/, serverReadyPattern: /- Local:/,
...@@ -166,10 +171,8 @@ describe.each([ ...@@ -166,10 +171,8 @@ describe.each([
NODE_ENV: sharedNodeEnv, NODE_ENV: sharedNodeEnv,
}, },
dependencies: sharedDeps, dependencies: sharedDeps,
skipDeployment: true,
disableAutoSkewProtection: true, disableAutoSkewProtection: true,
}) })
if (skipped) return
it('response includes etag header', async () => { it('response includes etag header', async () => {
const response = await fetchViaRawHttp(next.url, '/', tlsOpts) const response = await fetchViaRawHttp(next.url, '/', tlsOpts)
...@@ -177,8 +180,11 @@ describe.each([ ...@@ -177,8 +180,11 @@ describe.each([
}) })
}) })
// These tests start a custom Next.js server (server.js),
// which is not supported in deploy mode.
// @force-gate !deploy
describe('with generateEtags disabled', () => { describe('with generateEtags disabled', () => {
const { next, skipped } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
startCommand: 'node server.js', startCommand: 'node server.js',
serverReadyPattern: /- Local:/, serverReadyPattern: /- Local:/,
...@@ -188,10 +194,8 @@ describe.each([ ...@@ -188,10 +194,8 @@ describe.each([
NODE_ENV: sharedNodeEnv, NODE_ENV: sharedNodeEnv,
}, },
dependencies: sharedDeps, dependencies: sharedDeps,
skipDeployment: true,
disableAutoSkewProtection: true, disableAutoSkewProtection: true,
}) })
if (skipped) return
it('response does not include etag header', async () => { it('response does not include etag header', async () => {
const response = await fetchViaRawHttp(next.url, '/', tlsOpts) const response = await fetchViaRawHttp(next.url, '/', tlsOpts)
...@@ -200,8 +204,12 @@ describe.each([ ...@@ -200,8 +204,12 @@ describe.each([
}) })
if (useHttps === 'false') { if (useHttps === 'false') {
;(isNextDev ? describe : describe.skip)('HMR with custom server', () => { // These tests start a custom Next.js server (server.js),
const { next, skipped } = nextTestSetup({ // which is not supported in deploy mode.
// @force-gate !deploy
// @force-gate dev
describe('HMR with custom server', () => {
const { next } = nextTestSetup({
files: __dirname, files: __dirname,
startCommand: 'node server.js', startCommand: 'node server.js',
serverReadyPattern: /- Local:/, serverReadyPattern: /- Local:/,
...@@ -209,7 +217,6 @@ describe.each([ ...@@ -209,7 +217,6 @@ describe.each([
dependencies: sharedDeps, dependencies: sharedDeps,
disableAutoSkewProtection: true, disableAutoSkewProtection: true,
}) })
if (skipped) return
it('Should support HMR when rendering with /index pathname', async () => { it('Should support HMR when rendering with /index pathname', async () => {
const browser = await next.browser('/test-index-hmr') const browser = await next.browser('/test-index-hmr')
...@@ -244,17 +251,18 @@ describe.each([ ...@@ -244,17 +251,18 @@ describe.each([
}) })
} }
// These tests start a custom Next.js server (server.js),
// which is not supported in deploy mode.
// @force-gate !deploy
describe('Error when rendering without starting slash', () => { describe('Error when rendering without starting slash', () => {
const { next, skipped } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
startCommand: 'node server.js', startCommand: 'node server.js',
serverReadyPattern: /- Local:/, serverReadyPattern: /- Local:/,
env: { USE_HTTPS: useHttps, NODE_ENV: sharedNodeEnv }, env: { USE_HTTPS: useHttps, NODE_ENV: sharedNodeEnv },
dependencies: sharedDeps, dependencies: sharedDeps,
skipDeployment: true,
disableAutoSkewProtection: true, disableAutoSkewProtection: true,
}) })
if (skipped) return
;(isNextDev ? it : it.skip)('should warn in development mode', async () => { ;(isNextDev ? it : it.skip)('should warn in development mode', async () => {
const cliOutputBefore = next.cliOutput.length const cliOutputBefore = next.cliOutput.length
const html = await renderViaRawHTTP(next.url, '/no-slash', tlsOpts) const html = await renderViaRawHTTP(next.url, '/no-slash', tlsOpts)
...@@ -277,8 +285,11 @@ describe.each([ ...@@ -277,8 +285,11 @@ describe.each([
}) })
}) })
// These tests start a custom Next.js server (server.js),
// which is not supported in deploy mode.
// @force-gate !deploy
describe('with a custom fetch polyfill', () => { describe('with a custom fetch polyfill', () => {
const { next, skipped } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
startCommand: 'node server.js', startCommand: 'node server.js',
serverReadyPattern: /- Local:/, serverReadyPattern: /- Local:/,
...@@ -287,10 +298,8 @@ describe.each([ ...@@ -287,10 +298,8 @@ describe.each([
NODE_ENV: sharedNodeEnv, NODE_ENV: sharedNodeEnv,
}, },
dependencies: sharedDeps, dependencies: sharedDeps,
skipDeployment: true,
disableAutoSkewProtection: true, disableAutoSkewProtection: true,
}) })
if (skipped) return
it('should serve internal file from render', async () => { it('should serve internal file from render', async () => {
const html = await renderViaRawHTTP( const html = await renderViaRawHTTP(
...@@ -302,17 +311,18 @@ describe.each([ ...@@ -302,17 +311,18 @@ describe.each([
}) })
}) })
// These tests start a custom Next.js server (server.js),
// which is not supported in deploy mode.
// @force-gate !deploy
describe('unhandled rejection', () => { describe('unhandled rejection', () => {
const { next, skipped } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
startCommand: 'node server.js', startCommand: 'node server.js',
serverReadyPattern: /- Local:/, serverReadyPattern: /- Local:/,
env: { USE_HTTPS: useHttps, NODE_ENV: sharedNodeEnv }, env: { USE_HTTPS: useHttps, NODE_ENV: sharedNodeEnv },
dependencies: sharedDeps, dependencies: sharedDeps,
skipDeployment: true,
disableAutoSkewProtection: true, disableAutoSkewProtection: true,
}) })
if (skipped) return
it('stderr should include error message and stack trace', async () => { it('stderr should include error message and stack trace', async () => {
const cliOutputBefore = next.cliOutput.length const cliOutputBefore = next.cliOutput.length
...@@ -329,17 +339,18 @@ describe.each([ ...@@ -329,17 +339,18 @@ describe.each([
}) })
}) })
// These tests start a custom Next.js server (server.js),
// which is not supported in deploy mode.
// @force-gate !deploy
describe('legacy NextCustomServer methods', () => { describe('legacy NextCustomServer methods', () => {
const { next, skipped } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
startCommand: 'node server.js', startCommand: 'node server.js',
serverReadyPattern: /- Local:/, serverReadyPattern: /- Local:/,
env: { USE_HTTPS: useHttps, NODE_ENV: sharedNodeEnv }, env: { USE_HTTPS: useHttps, NODE_ENV: sharedNodeEnv },
dependencies: sharedDeps, dependencies: sharedDeps,
skipDeployment: true,
disableAutoSkewProtection: true, disableAutoSkewProtection: true,
}) })
if (skipped) return
it('NextCustomServer.renderToHTML', async () => { it('NextCustomServer.renderToHTML', async () => {
const rawHTML = await renderViaRawHTTP( const rawHTML = await renderViaRawHTTP(
......
...@@ -2544,10 +2544,12 @@ describe('opentelemetry with disabled fetch tracing', () => { ...@@ -2544,10 +2544,12 @@ describe('opentelemetry with disabled fetch tracing', () => {
) )
}) })
// These tests start a custom Next.js server (custom-server.ts),
// which is not supported in deploy mode.
// @force-gate !deploy
describe('opentelemetry with custom server', () => { describe('opentelemetry with custom server', () => {
const { next, skipped } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
skipDeployment: true,
skipStart: true, skipStart: true,
dependencies: require('./package.json').dependencies, dependencies: require('./package.json').dependencies,
startCommand: 'pnpm start', startCommand: 'pnpm start',
...@@ -2564,10 +2566,6 @@ describe('opentelemetry with custom server', () => { ...@@ -2564,10 +2566,6 @@ describe('opentelemetry with custom server', () => {
}, },
}) })
if (skipped) {
return
}
const getCollector = setupCollector(next, COLLECTOR_PORT) const getCollector = setupCollector(next, COLLECTOR_PORT)
it('should set attributes correctly on handleRequest span', async () => { it('should set attributes correctly on handleRequest span', async () => {
......
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