Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Nov 12, 2021
1 parent f02ddc5 commit 3d52f4d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
Expand Up @@ -41,7 +41,6 @@ export default async function middlewareRSCLoader(this: any) {
import App from ${stringifiedAbsoluteAppPath}
import Document from ${stringifiedAbsoluteDocumentPath}
let ErrorPage
try {
ErrorPage = require(${stringified500PagePath}).default
Expand Down Expand Up @@ -172,6 +171,7 @@ export default async function middlewareRSCLoader(this: any) {
const writer = transformStream.writable.getWriter()
const encoder = new TextEncoder()
let result
let renderError
let statusCode = 200
try {
result = await renderToHTML(
Expand All @@ -182,15 +182,28 @@ export default async function middlewareRSCLoader(this: any) {
renderOpts
)
} catch (err) {
renderError = err
statusCode = 500
const errorRes = { statusCode, err }
result = await renderToHTML(
req,
errorRes,
pathname,
query,
{ ...renderOpts, Component: ErrorPage }
)
}
if (renderError) {
try {
const errorRes = { statusCode, err: renderError }
result = await renderToHTML(
req,
errorRes,
pathname,
query,
{ ...renderOpts, Component: ErrorPage }
)
} catch (err) {
return new Response(
(err || 'An error occurred while rendering ' + pathname + '.').toString(),
{
status: 500,
headers: { 'x-middleware-ssr': '1' }
}
)
}
}
result.pipe({
Expand Down

This file was deleted.

Expand Up @@ -24,6 +24,7 @@ const nativeModuleTestAppDir = join(__dirname, '../unsupported-native-module')
const distDir = join(__dirname, '../app/.next')
const documentPage = new File(join(appDir, 'pages/_document.jsx'))
const appPage = new File(join(appDir, 'pages/_app.js'))
const error500Page = new File(join(appDir, 'pages/500.js'))

const documentWithGip = `
import { Html, Head, Main, NextScript } from 'next/document'
Expand Down Expand Up @@ -55,6 +56,12 @@ function App({ Component, pageProps }) {
export default App
`

const page500 = `
export default function Page500() {
return 'custom-500-page'
}
`

async function nextBuild(dir) {
return await _nextBuild(dir, [], {
stdout: true,
Expand Down Expand Up @@ -100,11 +107,13 @@ describe('concurrentFeatures - prod', () => {
const context = { appDir }

beforeAll(async () => {
error500Page.write(page500)
context.appPort = await findPort()
await nextBuild(context.appDir)
context.server = await nextStart(context.appDir, context.appPort)
})
afterAll(async () => {
error500Page.delete()
await killApp(context.server)
})

Expand Down Expand Up @@ -155,10 +164,12 @@ describe('concurrentFeatures - dev', () => {
const context = { appDir }

beforeAll(async () => {
error500Page.write(page500)
context.appPort = await findPort()
context.server = await nextDev(context.appDir, context.appPort)
})
afterAll(async () => {
error500Page.delete()
await killApp(context.server)
})

Expand Down

0 comments on commit 3d52f4d

Please sign in to comment.