Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Group edge ssr tests, merge `edge-vs.-non-edge-api-route-priority` and `react-18-streaming-ssr` into 1 e2e test suite - Add rewrite case to edge ssr in switchable runtime
- Loading branch information
Showing
18 changed files
with
221 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 0 additions & 33 deletions
33
test/e2e/edge-vs.-non-edge-api-route-priority/index.test.ts
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
import { join } from 'path' | ||
import { createNext, FileRef } from 'e2e-utils' | ||
import { NextInstance } from 'test/lib/next-modes/base' | ||
import { | ||
fetchViaHTTP, | ||
findPort, | ||
initNextServerScript, | ||
killApp, | ||
renderViaHTTP, | ||
} from 'next-test-utils' | ||
|
||
const react18Deps = { | ||
react: '^18.0.0', | ||
'react-dom': '^18.0.0', | ||
} | ||
|
||
const isNextProd = !(global as any).isNextDev && !(global as any).isNextDeploy | ||
|
||
describe('react 18 streaming SSR with custom next configs', () => { | ||
let next: NextInstance | ||
|
||
beforeAll(async () => { | ||
next = await createNext({ | ||
files: { | ||
pages: new FileRef(join(__dirname, 'streaming-ssr/pages')), | ||
}, | ||
nextConfig: require(join(__dirname, 'streaming-ssr/next.config.js')), | ||
dependencies: react18Deps, | ||
installCommand: 'npm install', | ||
}) | ||
}) | ||
afterAll(() => next.destroy()) | ||
|
||
it('should match more specific route along with dynamic routes', async () => { | ||
const res1 = await fetchViaHTTP(next.url, '/api/user/login') | ||
const res2 = await fetchViaHTTP(next.url, '/api/user/any') | ||
expect(await res1.text()).toBe('login') | ||
expect(await res2.text()).toBe('[id]') | ||
}) | ||
|
||
it('should render styled-jsx styles in streaming', async () => { | ||
const html = await renderViaHTTP(next.url, '/') | ||
expect(html).toContain('color:blue') | ||
}) | ||
|
||
it('should redirect paths without trailing-slash and render when slash is appended', async () => { | ||
const page = '/hello' | ||
const redirectRes = await fetchViaHTTP( | ||
next.url, | ||
page, | ||
{}, | ||
{ redirect: 'manual' } | ||
) | ||
const res = await fetchViaHTTP(next.url, page + '/') | ||
const html = await res.text() | ||
|
||
expect(redirectRes.status).toBe(308) | ||
expect(res.status).toBe(200) | ||
expect(html).toContain('hello nextjs') | ||
expect(html).toContain('home') | ||
}) | ||
|
||
it('should render multi-byte characters correctly in streaming', async () => { | ||
const html = await renderViaHTTP(next.url, '/multi-byte') | ||
expect(html).toContain('マルチバイト'.repeat(28)) | ||
}) | ||
}) | ||
|
||
if (isNextProd) { | ||
describe('react 18 streaming SSR with custom server', () => { | ||
let next | ||
let server | ||
let appPort | ||
beforeAll(async () => { | ||
next = await createNext({ | ||
files: { | ||
pages: new FileRef(join(__dirname, 'custom-server/pages')), | ||
'server.js': new FileRef(join(__dirname, 'custom-server/server.js')), | ||
}, | ||
nextConfig: require(join(__dirname, 'custom-server/next.config.js')), | ||
dependencies: react18Deps, | ||
}) | ||
await next.stop() | ||
|
||
const testServer = join(next.testDir, 'server.js') | ||
appPort = await findPort() | ||
server = await initNextServerScript( | ||
testServer, | ||
/Listening/, | ||
{ | ||
...process.env, | ||
PORT: appPort, | ||
}, | ||
undefined, | ||
{ | ||
cwd: next.testDir, | ||
} | ||
) | ||
}) | ||
afterAll(async () => { | ||
await next.destroy() | ||
if (server) await killApp(server) | ||
}) | ||
it('should render page correctly under custom server', async () => { | ||
const html = await renderViaHTTP(appPort, '/') | ||
expect(html).toContain('streaming') | ||
}) | ||
}) | ||
|
||
describe('react 18 streaming SSR in minimal mode with node runtime', () => { | ||
let next: NextInstance | ||
|
||
beforeAll(async () => { | ||
if (isNextProd) { | ||
process.env.NEXT_PRIVATE_MINIMAL_MODE = '1' | ||
} | ||
|
||
next = await createNext({ | ||
files: { | ||
'pages/index.js': ` | ||
export default function Page() { | ||
return <p>streaming</p> | ||
} | ||
export async function getServerSideProps() { | ||
return { props: {} } | ||
}`, | ||
}, | ||
nextConfig: { | ||
experimental: { | ||
runtime: 'nodejs', | ||
}, | ||
webpack(config, { nextRuntime }) { | ||
const path = require('path') | ||
const fs = require('fs') | ||
|
||
const runtimeFilePath = path.join(__dirname, 'runtimes.txt') | ||
let runtimeContent = '' | ||
|
||
try { | ||
runtimeContent = fs.readFileSync(runtimeFilePath, 'utf8') | ||
runtimeContent += '\n' | ||
} catch (_) {} | ||
|
||
runtimeContent += nextRuntime || 'client' | ||
|
||
fs.writeFileSync(runtimeFilePath, runtimeContent) | ||
return config | ||
}, | ||
}, | ||
dependencies: react18Deps, | ||
}) | ||
}) | ||
afterAll(() => { | ||
if (isNextProd) { | ||
delete process.env.NEXT_PRIVATE_MINIMAL_MODE | ||
} | ||
next.destroy() | ||
}) | ||
|
||
it('should pass correct nextRuntime values', async () => { | ||
const content = await next.readFile('runtimes.txt') | ||
expect(content.split('\n').sort()).toEqual(['client', 'edge', 'nodejs']) | ||
}) | ||
|
||
it('should generate html response by streaming correctly', async () => { | ||
const html = await renderViaHTTP(next.url, '/') | ||
expect(html).toContain('streaming') | ||
}) | ||
|
||
if (isNextProd) { | ||
it('should have generated a static 404 page', async () => { | ||
expect(await next.readFile('.next/server/pages/404.html')).toBeTruthy() | ||
|
||
const res = await fetchViaHTTP(next.url, '/non-existent') | ||
expect(res.status).toBe(404) | ||
expect(await res.text()).toContain('This page could not be found') | ||
}) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
trailingSlash: true, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default async function handler() { | ||
return new Response('[id]') | ||
} | ||
|
||
export const config = { | ||
runtime: 'experimental-edge', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default async function handler(_, res) { | ||
res.send('login') | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,22 @@ | ||
/** @type {import('next').NextConfig} */ | ||
module.exports = { | ||
reactStrictMode: true, | ||
experimental: { | ||
appDir: true, | ||
serverComponents: true, | ||
}, | ||
async rewrites() { | ||
return { | ||
afterFiles: [ | ||
{ | ||
source: '/rewrite/edge', | ||
destination: '/edge', | ||
}, | ||
{ | ||
source: '/rewrite/api/edge', | ||
destination: '/api/edge', | ||
}, | ||
], | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.