Unverified Commit c5a8e098 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Consolidate Server and Routing process into one process (#53523)

In the current version of Next.js there are 4 processes when running in
production:

- Server
- Routing
- Rendering Pages Router
- Rendering App Router

This setup was introduced in order to allow App Router and Pages Router
to use different versions of React (i.e. Server Actions currently
requires react@experimental to function). I wrote down more on why these
processes exist in this comment:
https://github.com/vercel/next.js/issues/49929#issuecomment-1637185156

This PR combines the Server and Routing process into one handler, as the
"Server" process was only proxying to the Routing process. In my testing
this caused about ~2x the amount of memory per request as the response
body was duplicated between the processes. This was especially visible
in the case of that memory leak in Node.js 18.16 as it grew memory usage
on both sides quickly.

In the process of going through these changes I found a couple of other
bugs like the propagation of values to the worker processes not being
awaited
([link](https://github.com/vercel/next.js/pull/53523/files#diff-0ef09f360141930bb03263b378d37d71ad9432ac851679aeabc577923536df84R54))
and the dot syntax for propagation was not functioning.

It also seemed there were a few cases where watchpack was used that
would cause many more files to be watched than expected, for now I've
removed those cases, specifically the "delete dir while running" and
instrument.js hmr (instrument.js is experimental). Those tests have been
skipped for now until we can revisit them to verfiy it

I've also cleaned up the types a bit while I was looking into these
changes.

### Improvement

⚠️ Important preface to this, measuring memory usage / peak usage is not
super reliable especially when JS gets garbage collected. These numbers
are just to show the rough percentage of less memory usage.

#### Baseline

Old:

```
next-server: 44.8MB
next-router-worker: 57.5MB
next-render-worker-app: 39,6MB
next-render-worker-pages: 39,1MB
```

New:

```
next-server: Removed
next-router-worker: 64.4MB
next-render-worker-app: 43.1MB (Note: no changes here, this shows what I meant by rough numbers)
next-render-worker-pages: 42.4MB (Note: no changes here, this shows what I meant by rough numbers)
```

Overall win: ~40MB (process is removed)

#### Peak usage

Old:

```
next-server: 118.6MB
next-router-worker: 223.7MB
next-render-worker-app: 32.8MB (I ran the test on a pages application in this case)
next-render-worker-pages: 101.1MB
```

New:

```
next-server: Removed
next-router-worker: 179.1MB
next-render-worker-app: 33.4MB
next-render-worker-pages: 117.5MB
```

Overall win: ~100MB (but it scales with requests so it was about ~50% of
next-router-worker constantly)

Related: #53523

---------
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent fef6f82a
This diff is collapsed.
...@@ -5,9 +5,6 @@ import { startServer } from '../server/lib/start-server' ...@@ -5,9 +5,6 @@ import { startServer } from '../server/lib/start-server'
import { getPort, printAndExit } from '../server/lib/utils' import { getPort, printAndExit } from '../server/lib/utils'
import { getProjectDir } from '../lib/get-project-dir' import { getProjectDir } from '../lib/get-project-dir'
import { CliCommand } from '../lib/commands' import { CliCommand } from '../lib/commands'
import { resolve } from 'path'
import { PHASE_PRODUCTION_SERVER } from '../shared/lib/constants'
import loadConfig from '../server/config'
import { getValidatedArgs } from '../lib/get-validated-args' import { getValidatedArgs } from '../lib/get-validated-args'
const nextStart: CliCommand = async (argv) => { const nextStart: CliCommand = async (argv) => {
...@@ -66,22 +63,12 @@ const nextStart: CliCommand = async (argv) => { ...@@ -66,22 +63,12 @@ const nextStart: CliCommand = async (argv) => {
? Math.ceil(keepAliveTimeoutArg) ? Math.ceil(keepAliveTimeoutArg)
: undefined : undefined
const config = await loadConfig(
PHASE_PRODUCTION_SERVER,
resolve(dir || '.'),
undefined,
undefined,
true
)
await startServer({ await startServer({
dir, dir,
nextConfig: config,
isDev: false, isDev: false,
hostname: host, hostname: host,
port, port,
keepAliveTimeout, keepAliveTimeout,
useWorkers: !!config.experimental.appDir,
}) })
} }
......
...@@ -468,6 +468,10 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -468,6 +468,10 @@ export default abstract class Server<ServerOptions extends Options = Options> {
this.responseCache = this.getResponseCache({ dev }) this.responseCache = this.getResponseCache({ dev })
} }
protected reloadMatchers() {
return this.matchers.reload()
}
protected async normalizeNextData( protected async normalizeNextData(
_req: BaseNextRequest, _req: BaseNextRequest,
_res: BaseNextResponse, _res: BaseNextResponse,
......
...@@ -87,7 +87,6 @@ export interface Options extends ServerOptions { ...@@ -87,7 +87,6 @@ export interface Options extends ServerOptions {
export default class DevServer extends Server { export default class DevServer extends Server {
private devReady: Promise<void> private devReady: Promise<void>
private setDevReady?: Function private setDevReady?: Function
private webpackWatcher?: any | null
protected sortedRoutes?: string[] protected sortedRoutes?: string[]
private pagesDir?: string private pagesDir?: string
private appDir?: string private appDir?: string
...@@ -247,15 +246,6 @@ export default class DevServer extends Server { ...@@ -247,15 +246,6 @@ export default class DevServer extends Server {
return 'development' return 'development'
} }
async stopWatcher(): Promise<void> {
if (!this.webpackWatcher) {
return
}
this.webpackWatcher.close()
this.webpackWatcher = null
}
protected async prepareImpl(): Promise<void> { protected async prepareImpl(): Promise<void> {
setGlobal('distDir', this.distDir) setGlobal('distDir', this.distDir)
setGlobal('phase', PHASE_DEVELOPMENT_SERVER) setGlobal('phase', PHASE_DEVELOPMENT_SERVER)
......
export function checkIsNodeDebugging() {
let isNodeDebugging: 'brk' | boolean = !!(
process.execArgv.some((localArg) => localArg.startsWith('--inspect')) ||
process.env.NODE_OPTIONS?.match?.(/--inspect(=\S+)?( |$)/)
)
if (
process.execArgv.some((localArg) => localArg.startsWith('--inspect-brk')) ||
process.env.NODE_OPTIONS?.match?.(/--inspect-brk(=\S+)?( |$)/)
) {
isNodeDebugging = 'brk'
}
return isNodeDebugging
}
...@@ -3,6 +3,7 @@ import type { RequestHandler } from '../next' ...@@ -3,6 +3,7 @@ import type { RequestHandler } from '../next'
// this must come first as it includes require hooks // this must come first as it includes require hooks
import { initializeServerWorker } from './setup-server-worker' import { initializeServerWorker } from './setup-server-worker'
import next from '../next' import next from '../next'
import { PropagateToWorkersField } from './router-utils/types'
export const WORKER_SELF_EXIT_CODE = 77 export const WORKER_SELF_EXIT_CODE = 77
...@@ -39,26 +40,18 @@ export function deleteCache(filePaths: string[]) { ...@@ -39,26 +40,18 @@ export function deleteCache(filePaths: string[]) {
} }
} }
export async function propagateServerField(field: string, value: any) { export async function propagateServerField(
field: PropagateToWorkersField,
value: any
) {
if (!app) { if (!app) {
throw new Error('Invariant cant propagate server field, no app initialized') throw new Error('Invariant cant propagate server field, no app initialized')
} }
let appField = (app as any).server let appField = (app as any).server
if (field.includes('.')) {
const parts = field.split('.')
for (let i = 0; i < parts.length - 1; i++) {
if (appField) {
appField = appField[parts[i]]
}
}
field = parts[parts.length - 1]
}
if (appField) { if (appField) {
if (typeof appField[field] === 'function') { if (typeof appField[field] === 'function') {
appField[field].apply( await appField[field].apply(
(app as any).server, (app as any).server,
Array.isArray(value) ? value : [] Array.isArray(value) ? value : []
) )
......
import type { IncomingMessage } from 'http' import type { IncomingMessage } from 'http'
// this must come first as it includes require hooks // this must come first as it includes require hooks
import { initializeServerWorker } from './setup-server-worker' import type {
WorkerRequestHandler,
WorkerUpgradeHandler,
} from './setup-server-worker'
import url from 'url' import url from 'url'
import path from 'path' import path from 'path'
...@@ -24,6 +27,7 @@ import { getResolveRoutes } from './router-utils/resolve-routes' ...@@ -24,6 +27,7 @@ import { getResolveRoutes } from './router-utils/resolve-routes'
import { NextUrlWithParsedQuery, getRequestMeta } from '../request-meta' import { NextUrlWithParsedQuery, getRequestMeta } from '../request-meta'
import { pathHasPrefix } from '../../shared/lib/router/utils/path-has-prefix' import { pathHasPrefix } from '../../shared/lib/router/utils/path-has-prefix'
import { removePathPrefix } from '../../shared/lib/router/utils/remove-path-prefix' import { removePathPrefix } from '../../shared/lib/router/utils/remove-path-prefix'
import setupCompression from 'next/dist/compiled/compression'
import { import {
PHASE_PRODUCTION_SERVER, PHASE_PRODUCTION_SERVER,
...@@ -32,13 +36,6 @@ import { ...@@ -32,13 +36,6 @@ import {
} from '../../shared/lib/constants' } from '../../shared/lib/constants'
import { signalFromNodeResponse } from '../web/spec-extension/adapters/next-request' import { signalFromNodeResponse } from '../web/spec-extension/adapters/next-request'
let initializeResult:
| undefined
| {
port: number
hostname: string
}
const debug = setupDebug('next:router-server:main') const debug = setupDebug('next:router-server:main')
export type RenderWorker = InstanceType< export type RenderWorker = InstanceType<
...@@ -51,6 +48,13 @@ export type RenderWorker = InstanceType< ...@@ -51,6 +48,13 @@ export type RenderWorker = InstanceType<
propagateServerField: typeof import('./render-server').propagateServerField propagateServerField: typeof import('./render-server').propagateServerField
} }
const nextDeleteCacheCallbacks: Array<(filePaths: string[]) => Promise<any>> =
[]
const nextDeleteAppClientCacheCallbacks: Array<() => Promise<any>> = []
const nextClearModuleContextCallbacks: Array<
(targetPath: string) => Promise<any>
> = []
export async function initialize(opts: { export async function initialize(opts: {
dir: string dir: string
port: number port: number
...@@ -61,10 +65,7 @@ export async function initialize(opts: { ...@@ -61,10 +65,7 @@ export async function initialize(opts: {
isNodeDebugging: boolean isNodeDebugging: boolean
keepAliveTimeout?: number keepAliveTimeout?: number
customServer?: boolean customServer?: boolean
}): Promise<NonNullable<typeof initializeResult>> { }): Promise<[WorkerRequestHandler, WorkerUpgradeHandler]> {
if (initializeResult) {
return initializeResult
}
process.title = 'next-router-worker' process.title = 'next-router-worker'
if (!process.env.NODE_ENV) { if (!process.env.NODE_ENV) {
...@@ -80,6 +81,12 @@ export async function initialize(opts: { ...@@ -80,6 +81,12 @@ export async function initialize(opts: {
true true
) )
let compress: ReturnType<typeof setupCompression> | undefined
if (config?.compress !== false) {
compress = setupCompression()
}
const fsChecker = await setupFsCheck({ const fsChecker = await setupFsCheck({
dev: opts.dev, dev: opts.dev,
dir: opts.dir, dir: opts.dir,
...@@ -207,39 +214,57 @@ export async function initialize(opts: { ...@@ -207,39 +214,57 @@ export async function initialize(opts: {
) )
// pre-initialize workers // pre-initialize workers
await renderWorkers.app?.initialize(renderWorkerOpts) const initialized = {
await renderWorkers.pages?.initialize(renderWorkerOpts) app: await renderWorkers.app?.initialize(renderWorkerOpts),
pages: await renderWorkers.pages?.initialize(renderWorkerOpts),
}
if (devInstance) { if (devInstance) {
Object.assign(devInstance.renderWorkers, renderWorkers) Object.assign(devInstance.renderWorkers, renderWorkers)
nextDeleteCacheCallbacks.push((filePaths: string[]) =>
Promise.all([
renderWorkers.pages?.deleteCache(filePaths),
renderWorkers.app?.deleteCache(filePaths),
])
)
nextDeleteAppClientCacheCallbacks.push(() =>
Promise.all([
renderWorkers.pages?.deleteAppClientCache(),
renderWorkers.app?.deleteAppClientCache(),
])
)
nextClearModuleContextCallbacks.push((targetPath: string) =>
Promise.all([
renderWorkers.pages?.clearModuleContext(targetPath),
renderWorkers.app?.clearModuleContext(targetPath),
])
)
;(global as any)._nextDeleteCache = async (filePaths: string[]) => { ;(global as any)._nextDeleteCache = async (filePaths: string[]) => {
try { for (const cb of nextDeleteCacheCallbacks) {
await Promise.all([ try {
renderWorkers.pages?.deleteCache(filePaths), await cb(filePaths)
renderWorkers.app?.deleteCache(filePaths), } catch (err) {
]) console.error(err)
} catch (err) { }
console.error(err)
} }
} }
;(global as any)._nextDeleteAppClientCache = async () => { ;(global as any)._nextDeleteAppClientCache = async () => {
try { for (const cb of nextDeleteAppClientCacheCallbacks) {
await Promise.all([ try {
renderWorkers.pages?.deleteAppClientCache(), await cb()
renderWorkers.app?.deleteAppClientCache(), } catch (err) {
]) console.error(err)
} catch (err) { }
console.error(err)
} }
} }
;(global as any)._nextClearModuleContext = async (targetPath: string) => { ;(global as any)._nextClearModuleContext = async (targetPath: string) => {
try { for (const cb of nextClearModuleContextCallbacks) {
await Promise.all([ try {
renderWorkers.pages?.clearModuleContext(targetPath), await cb(targetPath)
renderWorkers.app?.clearModuleContext(targetPath), } catch (err) {
]) console.error(err)
} catch (err) { }
console.error(err)
} }
} }
} }
...@@ -274,10 +299,11 @@ export async function initialize(opts: { ...@@ -274,10 +299,11 @@ export async function initialize(opts: {
devInstance?.ensureMiddleware devInstance?.ensureMiddleware
) )
const requestHandler: Parameters<typeof initializeServerWorker>[0] = async ( const requestHandler: WorkerRequestHandler = async (req, res) => {
req, if (compress) {
res // @ts-expect-error not express req/res
) => { compress(req, res, () => {})
}
req.on('error', (_err) => { req.on('error', (_err) => {
// TODO: log socket errors? // TODO: log socket errors?
}) })
...@@ -319,8 +345,7 @@ export async function initialize(opts: { ...@@ -319,8 +345,7 @@ export async function initialize(opts: {
return null return null
} }
const curWorker = renderWorkers[type] const workerResult = initialized[type]
const workerResult = await curWorker?.initialize(renderWorkerOpts)
if (!workerResult) { if (!workerResult) {
throw new Error(`Failed to initialize render worker ${type}`) throw new Error(`Failed to initialize render worker ${type}`)
...@@ -690,11 +715,7 @@ export async function initialize(opts: { ...@@ -690,11 +715,7 @@ export async function initialize(opts: {
} }
} }
const upgradeHandler: Parameters<typeof initializeServerWorker>[1] = async ( const upgradeHandler: WorkerUpgradeHandler = async (req, socket, head) => {
req,
socket,
head
) => {
try { try {
req.on('error', (_err) => { req.on('error', (_err) => {
// TODO: log socket errors? // TODO: log socket errors?
...@@ -735,16 +756,5 @@ export async function initialize(opts: { ...@@ -735,16 +756,5 @@ export async function initialize(opts: {
} }
} }
const { port, hostname } = await initializeServerWorker( return [requestHandler, upgradeHandler]
requestHandler,
upgradeHandler,
opts
)
initializeResult = {
port,
hostname: hostname === '0.0.0.0' ? '127.0.0.1' : hostname,
}
return initializeResult
} }
...@@ -17,7 +17,7 @@ import findUp from 'next/dist/compiled/find-up' ...@@ -17,7 +17,7 @@ import findUp from 'next/dist/compiled/find-up'
import { buildCustomRoute } from './filesystem' import { buildCustomRoute } from './filesystem'
import * as Log from '../../../build/output/log' import * as Log from '../../../build/output/log'
import HotReloader, { matchNextPageBundleRequest } from '../../dev/hot-reloader' import HotReloader, { matchNextPageBundleRequest } from '../../dev/hot-reloader'
import { traceGlobals } from '../../../trace/shared' import { setGlobal } from '../../../trace/shared'
import { Telemetry } from '../../../telemetry/storage' import { Telemetry } from '../../../telemetry/storage'
import { IncomingMessage, ServerResponse } from 'http' import { IncomingMessage, ServerResponse } from 'http'
import loadJsConfig from '../../../build/load-jsconfig' import loadJsConfig from '../../../build/load-jsconfig'
...@@ -79,6 +79,7 @@ import { PagesManifest } from '../../../build/webpack/plugins/pages-manifest-plu ...@@ -79,6 +79,7 @@ import { PagesManifest } from '../../../build/webpack/plugins/pages-manifest-plu
import { AppBuildManifest } from '../../../build/webpack/plugins/app-build-manifest-plugin' import { AppBuildManifest } from '../../../build/webpack/plugins/app-build-manifest-plugin'
import { PageNotFoundError } from '../../../shared/lib/utils' import { PageNotFoundError } from '../../../shared/lib/utils'
import { srcEmptySsgManifest } from '../../../build/webpack/plugins/build-manifest-plugin' import { srcEmptySsgManifest } from '../../../build/webpack/plugins/build-manifest-plugin'
import { PropagateToWorkersField } from './types'
import { MiddlewareManifest } from '../../../build/webpack/plugins/middleware-plugin' import { MiddlewareManifest } from '../../../build/webpack/plugins/middleware-plugin'
type SetupOpts = { type SetupOpts = {
...@@ -120,8 +121,8 @@ async function startWatcher(opts: SetupOpts) { ...@@ -120,8 +121,8 @@ async function startWatcher(opts: SetupOpts) {
const distDir = path.join(opts.dir, opts.nextConfig.distDir) const distDir = path.join(opts.dir, opts.nextConfig.distDir)
traceGlobals.set('distDir', distDir) setGlobal('distDir', distDir)
traceGlobals.set('phase', PHASE_DEVELOPMENT_SERVER) setGlobal('phase', PHASE_DEVELOPMENT_SERVER)
const validFileMatcher = createValidFileMatcher( const validFileMatcher = createValidFileMatcher(
nextConfig.pageExtensions, nextConfig.pageExtensions,
...@@ -133,7 +134,7 @@ async function startWatcher(opts: SetupOpts) { ...@@ -133,7 +134,7 @@ async function startWatcher(opts: SetupOpts) {
pages?: import('../router-server').RenderWorker pages?: import('../router-server').RenderWorker
} = {} } = {}
async function propagateToWorkers(field: string, args: any) { async function propagateToWorkers(field: PropagateToWorkersField, args: any) {
await renderWorkers.app?.propagateServerField(field, args) await renderWorkers.app?.propagateServerField(field, args)
await renderWorkers.pages?.propagateServerField(field, args) await renderWorkers.pages?.propagateServerField(field, args)
} }
...@@ -1010,7 +1011,7 @@ async function startWatcher(opts: SetupOpts) { ...@@ -1010,7 +1011,7 @@ async function startWatcher(opts: SetupOpts) {
hotReloader.setHmrServerError(new Error(errorMessage)) hotReloader.setHmrServerError(new Error(errorMessage))
} else if (numConflicting === 0) { } else if (numConflicting === 0) {
hotReloader.clearHmrServerError() hotReloader.clearHmrServerError()
await propagateToWorkers('matchers.reload', undefined) await propagateToWorkers('reloadMatchers', undefined)
} }
} }
...@@ -1279,7 +1280,7 @@ async function startWatcher(opts: SetupOpts) { ...@@ -1279,7 +1280,7 @@ async function startWatcher(opts: SetupOpts) {
} finally { } finally {
// Reload the matchers. The filesystem would have been written to, // Reload the matchers. The filesystem would have been written to,
// and the matchers need to re-scan it to update the router. // and the matchers need to re-scan it to update the router.
await propagateToWorkers('middleware.reload', undefined) await propagateToWorkers('reloadMatchers', undefined)
} }
}) })
......
export type PropagateToWorkersField =
| 'actualMiddlewareFile'
| 'actualInstrumentationHookFile'
| 'reloadMatchers'
| 'loadEnvConfig'
| 'appPathRoutes'
| 'middleware'
...@@ -22,9 +22,20 @@ export const WORKER_SELF_EXIT_CODE = 77 ...@@ -22,9 +22,20 @@ export const WORKER_SELF_EXIT_CODE = 77
const MAXIMUM_HEAP_SIZE_ALLOWED = const MAXIMUM_HEAP_SIZE_ALLOWED =
(v8.getHeapStatistics().heap_size_limit / 1024 / 1024) * 0.9 (v8.getHeapStatistics().heap_size_limit / 1024 / 1024) * 0.9
export type WorkerRequestHandler = (
req: IncomingMessage,
res: ServerResponse
) => Promise<any>
export type WorkerUpgradeHandler = (
req: IncomingMessage,
socket: Duplex,
head: Buffer
) => any
export async function initializeServerWorker( export async function initializeServerWorker(
requestHandler: (req: IncomingMessage, res: ServerResponse) => Promise<any>, requestHandler: WorkerRequestHandler,
upgradeHandler: (req: IncomingMessage, socket: Duplex, head: Buffer) => any, upgradeHandler: WorkerUpgradeHandler,
opts: { opts: {
dir: string dir: string
port: number port: number
......
import type arg from 'next/dist/compiled/arg/index.js' import type arg from 'next/dist/compiled/arg/index.js'
import * as Log from '../../build/output/log'
export function printAndExit(message: string, code = 1) { export function printAndExit(message: string, code = 1) {
if (code === 0) { if (code === 0) {
...@@ -34,15 +33,9 @@ export const genRouterWorkerExecArgv = async ( ...@@ -34,15 +33,9 @@ export const genRouterWorkerExecArgv = async (
}) })
if (isNodeDebugging) { if (isNodeDebugging) {
const isDebuggingWithBrk = isNodeDebugging === 'brk'
let debugPort = getDebugPort() + 1 let debugPort = getDebugPort() + 1
Log.info( // Process will log it's own debugger port
`the --inspect${
isDebuggingWithBrk ? '-brk' : ''
} option was detected, the Next.js routing server should be inspected at port ${debugPort}.`
)
execArgv.push( execArgv.push(
`--inspect${isNodeDebugging === 'brk' ? '-brk' : ''}=${debugPort}` `--inspect${isNodeDebugging === 'brk' ? '-brk' : ''}=${debugPort}`
......
This diff is collapsed.
...@@ -10,7 +10,7 @@ export type EventCliSessionStopped = { ...@@ -10,7 +10,7 @@ export type EventCliSessionStopped = {
appDir?: boolean appDir?: boolean
} }
export function eventCliSession( export function eventCliSessionStopped(
event: Omit<EventCliSessionStopped, 'nextVersion' | 'nodeVersion'> event: Omit<EventCliSessionStopped, 'nextVersion' | 'nodeVersion'>
): { eventName: string; payload: EventCliSessionStopped }[] { ): { eventName: string; payload: EventCliSessionStopped }[] {
// This should be an invariant, if it fails our build tooling is broken. // This should be an invariant, if it fails our build tooling is broken.
......
const nextConfig = {
reactStrictMode: true,
}
module.exports = nextConfig
export default function Page() {
return <p>hello world</p>
}
import { createNextDescribe } from 'e2e-utils' import { createNextDescribe } from 'e2e-utils'
import { check } from 'next-test-utils' import { check } from 'next-test-utils'
import { join } from 'path'
createNextDescribe( createNextDescribe(
'watch-config-file', 'watch-config-file',
{ {
files: { files: join(__dirname, 'fixture'),
'pages/index.js': `
export default function Page() {
return <p>hello world</p>
}
`,
'next.config.js': `
const nextConfig = {
reactStrictMode: true,
}
module.exports = nextConfig
`,
},
}, },
({ next }) => { ({ next }) => {
it('should output config file change', async () => { it('should output config file change', async () => {
...@@ -35,7 +22,7 @@ createNextDescribe( ...@@ -35,7 +22,7 @@ createNextDescribe(
{ {
source: '/about', source: '/about',
destination: '/', destination: '/',
permanent: true, permanent: false,
}, },
] ]
}, },
......
...@@ -26,7 +26,8 @@ createNextDescribe( ...@@ -26,7 +26,8 @@ createNextDescribe(
await check(() => next.cliOutput, /instrumentation hook on the edge/) await check(() => next.cliOutput, /instrumentation hook on the edge/)
}) })
if (isNextDev) { if (isNextDev) {
it('should reload the server when the instrumentation hook changes', async () => { // TODO: Implement handling for changing the instrument file.
it.skip('should reload the server when the instrumentation hook changes', async () => {
await next.render('/') await next.render('/')
await next.patchFile( await next.patchFile(
'./src/instrumentation.js', './src/instrumentation.js',
......
...@@ -104,7 +104,8 @@ describe('Instrumentation Hook', () => { ...@@ -104,7 +104,8 @@ describe('Instrumentation Hook', () => {
expect(page).toContain('Hello') expect(page).toContain('Hello')
}) })
if (isNextDev) { if (isNextDev) {
it('should reload the server when the instrumentation hook changes', async () => { // TODO: Implement handling for changing the instrument file.
it.skip('should reload the server when the instrumentation hook changes', async () => {
await next.render('/') await next.render('/')
await next.patchFile( await next.patchFile(
'./instrumentation.js', './instrumentation.js',
......
...@@ -9,7 +9,7 @@ import { join } from 'path' ...@@ -9,7 +9,7 @@ import { join } from 'path'
import fs from 'fs-extra' import fs from 'fs-extra'
import stripAnsi from 'strip-ansi' import stripAnsi from 'strip-ansi'
describe('Project Directory Delete Handling', () => { describe.skip('Project Directory Delete Handling', () => {
it('should gracefully exit on project dir delete', async () => { it('should gracefully exit on project dir delete', async () => {
const appDir = join(__dirname, 'app') const appDir = join(__dirname, 'app')
const appPort = await findPort() const appPort = await findPort()
......
/* eslint-env jest */ /* eslint-env jest */
import http from 'http'
import fs from 'fs-extra' import fs from 'fs-extra'
import { join } from 'path' import { join } from 'path'
import cheerio from 'cheerio' import cheerio from 'cheerio'
import { nextServer, waitFor } from 'next-test-utils' import { nextServer, startApp, waitFor } from 'next-test-utils'
import { import { fetchViaHTTP, nextBuild, renderViaHTTP } from 'next-test-utils'
fetchViaHTTP,
findPort,
nextBuild,
renderViaHTTP,
} from 'next-test-utils'
const appDir = join(__dirname, '..') const appDir = join(__dirname, '..')
let server let server
...@@ -18,7 +12,6 @@ let nextApp ...@@ -18,7 +12,6 @@ let nextApp
let appPort let appPort
let buildId let buildId
let requiredFilesManifest let requiredFilesManifest
let errors = []
describe('Required Server Files', () => { describe('Required Server Files', () => {
beforeAll(async () => { beforeAll(async () => {
...@@ -55,22 +48,10 @@ describe('Required Server Files', () => { ...@@ -55,22 +48,10 @@ describe('Required Server Files', () => {
quiet: false, quiet: false,
minimalMode: true, minimalMode: true,
}) })
await nextApp.prepare()
appPort = await findPort() server = await startApp(nextApp)
appPort = server.address().port
server = http.createServer(async (req, res) => {
try {
await nextApp.getRequestHandler()(req, res)
} catch (err) {
console.error('top-level', err)
errors.push(err)
res.statusCode = 500
res.end('error')
}
})
await new Promise((res, rej) => {
server.listen(appPort, (err) => (err ? rej(err) : res()))
})
console.log(`Listening at ::${appPort}`) console.log(`Listening at ::${appPort}`)
}) })
afterAll(async () => { afterAll(async () => {
...@@ -440,21 +421,18 @@ describe('Required Server Files', () => { ...@@ -440,21 +421,18 @@ describe('Required Server Files', () => {
}) })
it('should bubble error correctly for gip page', async () => { it('should bubble error correctly for gip page', async () => {
errors = []
const res = await fetchViaHTTP(appPort, '/errors/gip', { crash: '1' }) const res = await fetchViaHTTP(appPort, '/errors/gip', { crash: '1' })
expect(res.status).toBe(500) expect(res.status).toBe(500)
expect(await res.text()).toBe('Internal Server Error') expect(await res.text()).toBe('Internal Server Error')
}) })
it('should bubble error correctly for gssp page', async () => { it('should bubble error correctly for gssp page', async () => {
errors = []
const res = await fetchViaHTTP(appPort, '/errors/gssp', { crash: '1' }) const res = await fetchViaHTTP(appPort, '/errors/gssp', { crash: '1' })
expect(res.status).toBe(500) expect(res.status).toBe(500)
expect(await res.text()).toBe('Internal Server Error') expect(await res.text()).toBe('Internal Server Error')
}) })
it('should bubble error correctly for gsp page', async () => { it('should bubble error correctly for gsp page', async () => {
errors = []
const res = await fetchViaHTTP(appPort, '/errors/gsp/crash') const res = await fetchViaHTTP(appPort, '/errors/gsp/crash')
expect(res.status).toBe(500) expect(res.status).toBe(500)
expect(await res.text()).toBe('Internal Server Error') expect(await res.text()).toBe('Internal Server Error')
......
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