Unverified Commit 83b774ee authored by Shu Ding's avatar Shu Ding Committed by GitHub

Fix standalone mode with appDir running in a single process (#49116)

Fixes #49055, fixes #48918. 

App dir will always require the server to run in the workers mode, so it
can keep a separate Node.js process for pages. This PR updates the
standalone server to initialize a "standalone server" (which works
similar to `start-server`), and changes the tracked files to include
Jest worker.
parent c5406fc6
...@@ -51,7 +51,7 @@ app.prepare().then(() => { ...@@ -51,7 +51,7 @@ app.prepare().then(() => {
} catch (err) { } catch (err) {
console.error('Error occurred handling', req.url, err) console.error('Error occurred handling', req.url, err)
res.statusCode = 500 res.statusCode = 500
res.end('internal server error') res.end('Internal Server Error')
} }
}) })
.once('error', (err) => { .once('error', (err) => {
......
...@@ -1899,10 +1899,21 @@ export default async function build( ...@@ -1899,10 +1899,21 @@ export default async function build(
config.experimental?.turbotrace?.contextDirectory ?? config.experimental?.turbotrace?.contextDirectory ??
outputFileTracingRoot outputFileTracingRoot
// Under standalone mode, we need to trace the extra IPC server and
// worker files.
const isStandalone = config.output === 'standalone'
const nextServerEntry = require.resolve( const nextServerEntry = require.resolve(
'next/dist/server/next-server' 'next/dist/server/next-server'
) )
const toTrace = [nextServerEntry] const toTrace = [
nextServerEntry,
isStandalone
? require.resolve(
'next/dist/server/lib/render-server-standalone'
)
: null,
].filter(nonNullable)
// ensure we trace any dependencies needed for custom // ensure we trace any dependencies needed for custom
// incremental cache handler // incremental cache handler
...@@ -1927,7 +1938,7 @@ export default async function build( ...@@ -1927,7 +1938,7 @@ export default async function build(
'**/*.d.ts', '**/*.d.ts',
'**/*.map', '**/*.map',
'**/next/dist/pages/**/*', '**/next/dist/pages/**/*',
'**/next/dist/compiled/jest-worker/**/*', isStandalone ? null : '**/next/dist/compiled/jest-worker/**/*',
'**/next/dist/compiled/webpack/(bundle4|bundle5).js', '**/next/dist/compiled/webpack/(bundle4|bundle5).js',
'**/node_modules/webpack5/**/*', '**/node_modules/webpack5/**/*',
'**/next/dist/server/lib/squoosh/**/*.wasm', '**/next/dist/server/lib/squoosh/**/*.wasm',
...@@ -1944,7 +1955,8 @@ export default async function build( ...@@ -1944,7 +1955,8 @@ export default async function build(
? ['**/next/dist/compiled/@ampproject/toolbox-optimizer/**/*'] ? ['**/next/dist/compiled/@ampproject/toolbox-optimizer/**/*']
: []), : []),
...additionalIgnores, ...additionalIgnores,
] ].filter(nonNullable)
const ignoreFn = (pathname: string) => { const ignoreFn = (pathname: string) => {
if (path.isAbsolute(pathname) && !pathname.startsWith(root)) { if (path.isAbsolute(pathname) && !pathname.startsWith(root)) {
return true return true
...@@ -1957,6 +1969,26 @@ export default async function build( ...@@ -1957,6 +1969,26 @@ export default async function build(
} }
const traceContext = path.join(nextServerEntry, '..', '..') const traceContext = path.join(nextServerEntry, '..', '..')
const tracedFiles = new Set<string>() const tracedFiles = new Set<string>()
function addToTracedFiles(base: string, file: string) {
tracedFiles.add(
path
.relative(distDir, path.join(base, file))
.replace(/\\/g, '/')
)
}
if (isStandalone) {
addToTracedFiles(
'',
require.resolve('next/dist/compiled/jest-worker/processChild')
)
addToTracedFiles(
'',
require.resolve('next/dist/compiled/jest-worker/threadChild')
)
}
if (config.experimental.turbotrace) { if (config.experimental.turbotrace) {
const files: string[] = await nodeFileTrace( const files: string[] = await nodeFileTrace(
{ {
...@@ -1972,11 +2004,7 @@ export default async function build( ...@@ -1972,11 +2004,7 @@ export default async function build(
) )
for (const file of files) { for (const file of files) {
if (!ignoreFn(path.join(traceContext, file))) { if (!ignoreFn(path.join(traceContext, file))) {
tracedFiles.add( addToTracedFiles(traceContext, file)
path
.relative(distDir, path.join(traceContext, file))
.replace(/\\/g, '/')
)
} }
} }
} else { } else {
...@@ -1987,11 +2015,7 @@ export default async function build( ...@@ -1987,11 +2015,7 @@ export default async function build(
}) })
serverResult.fileList.forEach((file) => { serverResult.fileList.forEach((file) => {
tracedFiles.add( addToTracedFiles(root, file)
path
.relative(distDir, path.join(root, file))
.replace(/\\/g, '/')
)
}) })
} }
await promises.writeFile( await promises.writeFile(
......
...@@ -1913,17 +1913,20 @@ export async function copyTracedFiles( ...@@ -1913,17 +1913,20 @@ export async function copyTracedFiles(
serverOutputPath, serverOutputPath,
`${ `${
moduleType moduleType
? `import Server from 'next/dist/server/next-server.js' ? `import http from 'http'
import http from 'http'
import path from 'path' import path from 'path'
import { fileURLToPath } from 'url' import { fileURLToPath } from 'url'
const __dirname = fileURLToPath(new URL('.', import.meta.url)) const __dirname = fileURLToPath(new URL('.', import.meta.url))
const NextServer = Server.default` import { createServerHandler } from 'next/dist/server/lib/render-server-standalone.js'
`
: ` : `
const NextServer = require('next/dist/server/next-server').default
const http = require('http') const http = require('http')
const path = require('path')` const path = require('path')
const { createServerHandler } = require('next/dist/server/lib/render-server-standalone')`
} }
const dir = path.join(__dirname)
process.env.NODE_ENV = 'production' process.env.NODE_ENV = 'production'
process.chdir(__dirname) process.chdir(__dirname)
...@@ -1944,16 +1947,7 @@ const nextConfig = ${JSON.stringify({ ...@@ -1944,16 +1947,7 @@ const nextConfig = ${JSON.stringify({
distDir: `./${path.relative(dir, distDir)}`, distDir: `./${path.relative(dir, distDir)}`,
})} })}
${ process.env.__NEXT_PRIVATE_STANDALONE_CONFIG = JSON.stringify(nextConfig)
// In standalone mode, we don't have separated render workers so if both
// app and pages are used, we need to resolve to the prebundled React
// to ensure the correctness of the version for app.
`\
if (nextConfig && nextConfig.experimental && nextConfig.experimental.appDir) {
process.env.__NEXT_PRIVATE_PREBUNDLED_REACT = nextConfig.experimental.serverActions ? 'experimental' : 'next'
}
`
}
const server = http.createServer(async (req, res) => { const server = http.createServer(async (req, res) => {
try { try {
...@@ -1961,7 +1955,7 @@ const server = http.createServer(async (req, res) => { ...@@ -1961,7 +1955,7 @@ const server = http.createServer(async (req, res) => {
} catch (err) { } catch (err) {
console.error(err); console.error(err);
res.statusCode = 500 res.statusCode = 500
res.end('internal server error') res.end('Internal Server Error')
} }
}) })
...@@ -1972,20 +1966,18 @@ if ( ...@@ -1972,20 +1966,18 @@ if (
) { ) {
server.keepAliveTimeout = keepAliveTimeout server.keepAliveTimeout = keepAliveTimeout
} }
server.listen(currentPort, (err) => { server.listen(currentPort, async (err) => {
if (err) { if (err) {
console.error("Failed to start server", err) console.error("Failed to start server", err)
process.exit(1) process.exit(1)
} }
const nextServer = new NextServer({
hostname, handler = await createServerHandler({
port: currentPort, port: currentPort,
dir: path.join(__dirname), hostname,
dev: false, dir,
customServer: false,
conf: nextConfig, conf: nextConfig,
}) })
handler = nextServer.getRequestHandler()
console.log( console.log(
'Listening on port', 'Listening on port',
......
...@@ -689,6 +689,10 @@ export default async function loadConfig( ...@@ -689,6 +689,10 @@ export default async function loadConfig(
rawConfig?: boolean, rawConfig?: boolean,
silent?: boolean silent?: boolean
): Promise<NextConfigComplete> { ): Promise<NextConfigComplete> {
if (process.env.__NEXT_PRIVATE_STANDALONE_CONFIG) {
return JSON.parse(process.env.__NEXT_PRIVATE_STANDALONE_CONFIG)
}
const curLog = silent const curLog = silent
? { ? {
warn: () => {}, warn: () => {},
......
...@@ -460,7 +460,7 @@ export async function optimizeImage({ ...@@ -460,7 +460,7 @@ export async function optimizeImage({
console.error( console.error(
`Error: 'sharp' is required to be installed in standalone mode for the image optimization to function correctly. Read more at: https://nextjs.org/docs/messages/sharp-missing-in-production` `Error: 'sharp' is required to be installed in standalone mode for the image optimization to function correctly. Read more at: https://nextjs.org/docs/messages/sharp-missing-in-production`
) )
throw new ImageError(500, 'internal server error') throw new ImageError(500, 'Internal Server Error')
} }
// Show sharp warning in production once // Show sharp warning in production once
if (showSharpMissingWarning) { if (showSharpMissingWarning) {
......
import type { IncomingMessage, ServerResponse } from 'http'
import type { ChildProcess } from 'child_process'
import httpProxy from 'next/dist/compiled/http-proxy'
import { Worker } from 'next/dist/compiled/jest-worker'
import { normalizeRepeatedSlashes } from '../../shared/lib/utils'
const renderServerPath = require.resolve('./render-server')
export const createServerHandler = async ({
port,
hostname,
dir,
minimalMode,
}: {
port: number
hostname: string
dir: string
minimalMode: boolean
}) => {
const routerWorker = new Worker(renderServerPath, {
numWorkers: 1,
maxRetries: 10,
forkOptions: {
env: {
FORCE_COLOR: '1',
...process.env,
},
},
exposedMethods: ['initialize'],
}) as any as InstanceType<typeof Worker> & {
initialize: typeof import('./render-server').initialize
}
let didInitialize = false
for (const _worker of ((routerWorker as any)._workerPool?._workers || []) as {
_child: ChildProcess
}[]) {
// eslint-disable-next-line no-loop-func
_worker._child.on('exit', (code, signal) => {
// catch failed initializing without retry
if ((code || signal) && !didInitialize) {
routerWorker?.end()
process.exit(1)
}
})
}
const workerStdout = routerWorker.getStdout()
const workerStderr = routerWorker.getStderr()
workerStdout.on('data', (data) => {
process.stdout.write(data)
})
workerStderr.on('data', (data) => {
process.stderr.write(data)
})
const { port: routerPort } = await routerWorker.initialize({
dir,
port,
dev: false,
hostname,
minimalMode,
workerType: 'router',
})
didInitialize = true
const getProxyServer = (pathname: string) => {
const targetUrl = `http://${hostname}:${routerPort}${pathname}`
const proxyServer = httpProxy.createProxy({
target: targetUrl,
changeOrigin: false,
ignorePath: true,
xfwd: true,
ws: true,
followRedirects: false,
})
return proxyServer
}
// proxy to router worker
return async (req: IncomingMessage, res: ServerResponse) => {
const urlParts = (req.url || '').split('?')
const urlNoQuery = urlParts[0]
// this normalizes repeated slashes in the path e.g. hello//world ->
// hello/world or backslashes to forward slashes, this does not
// handle trailing slash as that is handled the same as a next.config.js
// redirect
if (urlNoQuery?.match(/(\\|\/\/)/)) {
const cleanUrl = normalizeRepeatedSlashes(req.url!)
res.statusCode = 308
res.setHeader('Location', cleanUrl)
res.end(cleanUrl)
return
}
const proxyServer = getProxyServer(req.url || '/')
proxyServer.web(req, res)
proxyServer.on('error', (err) => {
res.statusCode = 500
res.end('Internal Server Error')
console.error(err)
})
}
}
...@@ -42,6 +42,7 @@ export async function initialize(opts: { ...@@ -42,6 +42,7 @@ export async function initialize(opts: {
dir: string dir: string
port: number port: number
dev: boolean dev: boolean
minimalMode?: boolean
hostname?: string hostname?: string
workerType: 'router' | 'render' workerType: 'router' | 'render'
keepAliveTimeout?: number keepAliveTimeout?: number
...@@ -54,18 +55,24 @@ export async function initialize(opts: { ...@@ -54,18 +55,24 @@ export async function initialize(opts: {
let requestHandler: RequestHandler let requestHandler: RequestHandler
const server = http.createServer((req, res) => { const server = http.createServer((req, res) => {
return requestHandler(req, res).finally(() => { return requestHandler(req, res)
if ( .catch((err) => {
process.memoryUsage().heapUsed / 1024 / 1024 > res.statusCode = 500
MAXIMUM_HEAP_SIZE_ALLOWED res.end('Internal Server Error')
) { console.error(err)
warn( })
'The server is running out of memory, restarting to free up memory.' .finally(() => {
) if (
server.close() process.memoryUsage().heapUsed / 1024 / 1024 >
process.exit(WORKER_SELF_EXIT_CODE) MAXIMUM_HEAP_SIZE_ALLOWED
} ) {
}) warn(
'The server is running out of memory, restarting to free up memory.'
)
server.close()
process.exit(WORKER_SELF_EXIT_CODE)
}
})
}) })
if (opts.keepAliveTimeout) { if (opts.keepAliveTimeout) {
......
...@@ -104,6 +104,8 @@ export const createWorker = ( ...@@ -104,6 +104,8 @@ export const createWorker = (
__NEXT_PRIVATE_RENDER_WORKER: type, __NEXT_PRIVATE_RENDER_WORKER: type,
__NEXT_PRIVATE_ROUTER_IPC_PORT: ipcPort + '', __NEXT_PRIVATE_ROUTER_IPC_PORT: ipcPort + '',
__NEXT_PRIVATE_ROUTER_IPC_KEY: ipcValidationKey, __NEXT_PRIVATE_ROUTER_IPC_KEY: ipcValidationKey,
__NEXT_PRIVATE_STANDALONE_CONFIG:
process.env.__NEXT_PRIVATE_STANDALONE_CONFIG,
NODE_ENV: process.env.NODE_ENV, NODE_ENV: process.env.NODE_ENV,
...(type === 'app' ...(type === 'app'
? { ? {
......
...@@ -263,6 +263,7 @@ export default class NextNodeServer extends BaseServer { ...@@ -263,6 +263,7 @@ export default class NextNodeServer extends BaseServer {
dir: this.dir, dir: this.dir,
workerType: 'render', workerType: 'render',
hostname: this.hostname, hostname: this.hostname,
minimalMode: this.minimalMode,
dev: !!options.dev, dev: !!options.dev,
} }
const { createWorker, createIpcServer } = const { createWorker, createIpcServer } =
......
...@@ -169,9 +169,11 @@ export class NextServer { ...@@ -169,9 +169,11 @@ export class NextServer {
this.serverPromise = this.loadConfig().then(async (conf) => { this.serverPromise = this.loadConfig().then(async (conf) => {
if (!this.options.dev) { if (!this.options.dev) {
if (conf.output === 'standalone') { if (conf.output === 'standalone') {
log.warn( if (!process.env.__NEXT_PRIVATE_STANDALONE_CONFIG) {
`"next start" does not work with "output: standalone" configuration. Use "node .next/standalone/server.js" instead.` log.warn(
) `"next start" does not work with "output: standalone" configuration. Use "node .next/standalone/server.js" instead.`
)
}
} else if (conf.output === 'export') { } else if (conf.output === 'export') {
throw new Error( throw new Error(
`"next start" does not work with "output: export" configuration. Use "npx serve@latest out" instead.` `"next start" does not work with "output: export" configuration. Use "npx serve@latest out" instead.`
......
...@@ -14,7 +14,7 @@ const server = http.createServer(async (req, res) => { ...@@ -14,7 +14,7 @@ const server = http.createServer(async (req, res) => {
} catch (err) { } catch (err) {
console.error(err) console.error(err)
res.statusCode = 500 res.statusCode = 500
res.end('internal server error') res.end('Internal Server Error')
} }
}) })
const currentPort = parseInt(process.env.PORT, 10) || 3000 const currentPort = parseInt(process.env.PORT, 10) || 3000
......
...@@ -25,7 +25,7 @@ describe('Handles an Error in _error', () => { ...@@ -25,7 +25,7 @@ describe('Handles an Error in _error', () => {
it('Handles error during SSR', async () => { it('Handles error during SSR', async () => {
const html = await renderViaHTTP(port, '/some-404-page') const html = await renderViaHTTP(port, '/some-404-page')
expect(html).toMatch(/internal server error/i) expect(html).toMatch(/Internal Server Error/i)
}) })
it('Handles error during client transition', async () => { it('Handles error during client transition', async () => {
...@@ -33,6 +33,6 @@ describe('Handles an Error in _error', () => { ...@@ -33,6 +33,6 @@ describe('Handles an Error in _error', () => {
await browser.waitForElementByCss('a').click() await browser.waitForElementByCss('a').click()
await waitFor(1000) await waitFor(1000)
const html = await browser.eval('document.body.innerHTML') const html = await browser.eval('document.body.innerHTML')
expect(html).toMatch(/internal server error/i) expect(html).toMatch(/Internal Server Error/i)
}) })
}) })
...@@ -83,7 +83,7 @@ describe('i18n Support', () => { ...@@ -83,7 +83,7 @@ describe('i18n Support', () => {
'utf8' 'utf8'
) )
expect(content).toContain('500') expect(content).toContain('500')
expect(content).toMatch(/internal server error/i) expect(content).toMatch(/Internal Server Error/i)
} }
}) })
}) })
......
...@@ -26,7 +26,7 @@ app.prepare().then(() => { ...@@ -26,7 +26,7 @@ app.prepare().then(() => {
} catch (err) { } catch (err) {
console.error('Error occurred handling', req.url, err) console.error('Error occurred handling', req.url, err)
res.statusCode = 500 res.statusCode = 500
res.end('internal server error') res.end('Internal Server Error')
} }
}).listen(port, (err) => { }).listen(port, (err) => {
if (err) throw err if (err) throw err
......
...@@ -71,9 +71,9 @@ describe('should set-up next', () => { ...@@ -71,9 +71,9 @@ describe('should set-up next', () => {
const testServer = join(next.testDir, 'standalone/server.js') const testServer = join(next.testDir, 'standalone/server.js')
await fs.writeFile( await fs.writeFile(
testServer, testServer,
(await fs.readFile(testServer, 'utf8')) (
.replace('console.error(err)', `console.error('top-level', err)`) await fs.readFile(testServer, 'utf8')
.replace('conf:', `minimalMode: ${minimalMode},conf:`) ).replace('conf:', `minimalMode: ${minimalMode},conf:`)
) )
appPort = await findPort() appPort = await findPort()
server = await initNextServerScript( server = await initNextServerScript(
......
...@@ -105,9 +105,9 @@ describe('should set-up next', () => { ...@@ -105,9 +105,9 @@ describe('should set-up next', () => {
const testServer = join(next.testDir, 'standalone/server.js') const testServer = join(next.testDir, 'standalone/server.js')
await fs.writeFile( await fs.writeFile(
testServer, testServer,
(await fs.readFile(testServer, 'utf8')) (
.replace('console.error(err)', `console.error('top-level', err)`) await fs.readFile(testServer, 'utf8')
.replace('conf:', 'minimalMode: true,conf:') ).replace('conf:', 'minimalMode: true,conf:')
) )
appPort = await findPort() appPort = await findPort()
server = await initNextServerScript( server = await initNextServerScript(
...@@ -121,9 +121,7 @@ describe('should set-up next', () => { ...@@ -121,9 +121,7 @@ describe('should set-up next', () => {
{ {
cwd: next.testDir, cwd: next.testDir,
onStderr(msg) { onStderr(msg) {
if (msg.includes('top-level')) { errors.push(msg)
errors.push(msg)
}
}, },
} }
) )
...@@ -592,7 +590,7 @@ describe('should set-up next', () => { ...@@ -592,7 +590,7 @@ describe('should set-up next', () => {
errors = [] 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')
await check( await check(
() => (errors[0].includes('gip hit an oops') ? 'success' : errors[0]), () => (errors[0].includes('gip hit an oops') ? 'success' : errors[0]),
...@@ -604,7 +602,7 @@ describe('should set-up next', () => { ...@@ -604,7 +602,7 @@ describe('should set-up next', () => {
errors = [] 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')
await check( await check(
() => (errors[0].includes('gssp hit an oops') ? 'success' : errors[0]), () => (errors[0].includes('gssp hit an oops') ? 'success' : errors[0]),
'success' 'success'
...@@ -615,7 +613,7 @@ describe('should set-up next', () => { ...@@ -615,7 +613,7 @@ describe('should set-up next', () => {
errors = [] 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')
await check( await check(
() => (errors[0].includes('gsp hit an oops') ? 'success' : errors[0]), () => (errors[0].includes('gsp hit an oops') ? 'success' : errors[0]),
'success' 'success'
...@@ -626,7 +624,7 @@ describe('should set-up next', () => { ...@@ -626,7 +624,7 @@ describe('should set-up next', () => {
errors = [] errors = []
const res = await fetchViaHTTP(appPort, '/api/error') const res = await fetchViaHTTP(appPort, '/api/error')
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')
await check( await check(
() => () =>
errors[0].includes('some error from /api/error') errors[0].includes('some error from /api/error')
......
...@@ -107,9 +107,9 @@ describe('should set-up next', () => { ...@@ -107,9 +107,9 @@ describe('should set-up next', () => {
const testServer = join(next.testDir, 'standalone/server.js') const testServer = join(next.testDir, 'standalone/server.js')
await fs.writeFile( await fs.writeFile(
testServer, testServer,
(await fs.readFile(testServer, 'utf8')) (
.replace('console.error(err)', `console.error('top-level', err)`) await fs.readFile(testServer, 'utf8')
.replace('conf:', `minimalMode: ${minimalMode},conf:`) ).replace('conf:', `minimalMode: ${minimalMode},conf:`)
) )
appPort = await findPort() appPort = await findPort()
server = await initNextServerScript( server = await initNextServerScript(
...@@ -123,9 +123,7 @@ describe('should set-up next', () => { ...@@ -123,9 +123,7 @@ describe('should set-up next', () => {
{ {
cwd: next.testDir, cwd: next.testDir,
onStderr(msg) { onStderr(msg) {
if (msg.includes('top-level')) { errors.push(msg)
errors.push(msg)
}
stderr += msg stderr += msg
}, },
} }
...@@ -941,7 +939,7 @@ describe('should set-up next', () => { ...@@ -941,7 +939,7 @@ describe('should set-up next', () => {
errors = [] 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')
await check( await check(
() => (errors[0].includes('gip hit an oops') ? 'success' : errors[0]), () => (errors[0].includes('gip hit an oops') ? 'success' : errors[0]),
...@@ -953,7 +951,7 @@ describe('should set-up next', () => { ...@@ -953,7 +951,7 @@ describe('should set-up next', () => {
errors = [] 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')
await check( await check(
() => (errors[0].includes('gssp hit an oops') ? 'success' : errors[0]), () => (errors[0].includes('gssp hit an oops') ? 'success' : errors[0]),
'success' 'success'
...@@ -964,7 +962,7 @@ describe('should set-up next', () => { ...@@ -964,7 +962,7 @@ describe('should set-up next', () => {
errors = [] 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')
await check( await check(
() => (errors[0].includes('gsp hit an oops') ? 'success' : errors[0]), () => (errors[0].includes('gsp hit an oops') ? 'success' : errors[0]),
'success' 'success'
...@@ -975,7 +973,7 @@ describe('should set-up next', () => { ...@@ -975,7 +973,7 @@ describe('should set-up next', () => {
errors = [] errors = []
const res = await fetchViaHTTP(appPort, '/api/error') const res = await fetchViaHTTP(appPort, '/api/error')
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')
await check( await check(
() => () =>
errors[0].includes('some error from /api/error') errors[0].includes('some error from /api/error')
...@@ -1280,9 +1278,7 @@ describe('should set-up next', () => { ...@@ -1280,9 +1278,7 @@ describe('should set-up next', () => {
{ {
cwd: next.testDir, cwd: next.testDir,
onStderr(msg) { onStderr(msg) {
if (msg.includes('top-level')) { errors.push(msg)
errors.push(msg)
}
stderr += msg stderr += msg
}, },
} }
......
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