Unverified Commit 70231ef7 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

test: add case for marking _document with edge runtime (#54316)

Can't repro anymore, add a test case for issue 45189

Closes #45189
Closes NEXT-1396
parent 0e91c79f
import { createNextDescribe } from 'e2e-utils'
import { join } from 'path'
// x-ref: https://github.com/vercel/next.js/issues/45189
createNextDescribe(
'edge render - custom _document with edge runtime',
{
files: join(__dirname, 'app'),
},
({ next }) => {
beforeAll(async () => {
await next.stop()
await next.patchFile(
'pages/_document.js',
`import Document, { Html, Head, Main, NextScript } from 'next/document'
export default class MyDocument extends Document {
render() {
return (
<Html>
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
}
export const config = {
runtime: 'experimental-edge',
}
`
)
await next.start()
})
afterAll(async () => {
await next.deleteFile('pages/_document.js')
})
it('should render page properly', async () => {
const $ = await next.render$('/')
expect($('#page').text()).toBe('/index')
})
}
)
import { createNext, FileRef } from 'e2e-utils' import { createNextDescribe } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { fetchViaHTTP, normalizeRegEx } from 'next-test-utils' import { fetchViaHTTP, normalizeRegEx } from 'next-test-utils'
import cheerio from 'cheerio' import cheerio from 'cheerio'
import { join } from 'path' import { join } from 'path'
import escapeStringRegexp from 'escape-string-regexp' import escapeStringRegexp from 'escape-string-regexp'
import fs from 'fs-extra' import fs from 'fs-extra'
describe('edge-render-getserversideprops', () => { createNextDescribe(
let next: NextInstance 'edge-render-getserversideprops',
{
beforeAll(async () => { files: join(__dirname, 'app'),
next = await createNext({ },
files: new FileRef(join(__dirname, 'app')), ({ next }) => {
dependencies: {},
})
})
afterAll(() => next.destroy())
if ((global as any).isNextStart) { if ((global as any).isNextStart) {
it('should not output trace files for edge routes', async () => { it('should not output trace files for edge routes', async () => {
expect(await fs.pathExists(join(next.testDir, '.next/pages'))).toBe(false) expect(await fs.pathExists(join(next.testDir, '.next/pages'))).toBe(
false
)
expect( expect(
await fs.pathExists(join(next.testDir, '.next/server/pages/[id].js')) await fs.pathExists(join(next.testDir, '.next/server/pages/[id].js'))
).toBe(true) ).toBe(true)
...@@ -167,7 +163,9 @@ describe('edge-render-getserversideprops', () => { ...@@ -167,7 +163,9 @@ describe('edge-render-getserversideprops', () => {
}, },
{ {
dataRouteRegex: normalizeRegEx( dataRouteRegex: normalizeRegEx(
`^/_next/data/${escapeStringRegexp(next.buildId)}/([^/]+?)\\.json$` `^/_next/data/${escapeStringRegexp(
next.buildId
)}/([^/]+?)\\.json$`
), ),
namedDataRouteRegex: `^/_next/data/${escapeStringRegexp( namedDataRouteRegex: `^/_next/data/${escapeStringRegexp(
next.buildId next.buildId
...@@ -180,4 +178,5 @@ describe('edge-render-getserversideprops', () => { ...@@ -180,4 +178,5 @@ describe('edge-render-getserversideprops', () => {
]) ])
}) })
} }
}) }
)
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