Unverified Commit f7de771b authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Migrate rsc integration tests to e2e tests (#38460)

* Migrate rsc integration tests to e2e tests

* skip image test

* remove image page
Co-authored-by: 's avatarkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
parent 689626c6
import React from 'react'
export default function AppLayout({ children }) {
return (
<html>
<head>
<title>RSC</title>
</head>
<body>{children}</body>
</html>
)
}
......@@ -16,7 +16,9 @@ export default function LinkPage({ queryId }) {
)
}
export function getServerSideProps({ query }) {
export function getServerSideProps(ctx) {
// FIXME: query is missing
const { query } = ctx
return {
props: {
queryId: query.id || '0',
......
......@@ -14,8 +14,8 @@ export default function Index({ header }) {
)
}
export function getServerSideProps({ req }) {
const { headers } = req
export function getServerSideProps(ctx) {
const { headers } = ctx
const header = headers[headerKey] || ''
return {
......
......@@ -3,7 +3,6 @@ module.exports = {
onDemandEntries: {
maxInactiveAge: 1000 * 60 * 60,
},
pageExtensions: ['js', 'ts', 'jsx'], // .tsx won't be treat as page,
experimental: {
appDir: true,
runtime: 'nodejs',
......
export default function InvalidExt() {
return 'invalid-ext'
}
import { NextResponse } from 'next/server'
export async function middleware(req) {
return NextResponse.next()
}
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"include": ["next-env.d.ts", "**/*.ts"],
"exclude": ["node_modules"]
}
/* eslint-env jest */
/* eslint-disable jest/no-commented-out-tests */
import { join } from 'path'
import fs from 'fs-extra'
import { runDevSuite, runProdSuite } from 'next-test-utils'
import rsc from './rsc'
const appDir = join(__dirname, '../basic')
const nodeArgs = [
'-r',
join(appDir, '../../../lib/react-channel-require-hook.js'),
]
/* TODO: support edge runtime in the future
const edgeRuntimeBasicSuite = {
runTests: (context, env) => {
const options = { runtime: 'experimental-edge', env }
const distDir = join(appDir, '.next')
streaming(context, options)
// rsc(context, options)
if (env === 'dev') {
it.skip('should have content-type and content-encoding headers', async () => {
// TODO: fix the compression header issue for `/`
const res = await fetchViaHTTP(context.appPort, '/shared')
expect(res.headers.get('content-type')).toBe('text/html; charset=utf-8')
expect(res.headers.get('content-encoding')).toBe('gzip')
})
}
if (env === 'prod') {
it.skip('should warn user for experimental risk with edge runtime and server components', async () => {
const edgeRuntimeWarning =
'You are using the experimental Edge Runtime with `experimental.runtime`.'
const rscWarning = `You have experimental React Server Components enabled. Continue at your own risk.`
expect(context.stderr).toContain(edgeRuntimeWarning)
expect(context.stderr).toContain(rscWarning)
})
it.skip('should generate edge SSR manifests for edge runtime', async () => {
const distServerDir = join(distDir, 'server')
const files = [
'edge-runtime-webpack.js',
'middleware-build-manifest.js',
'middleware-manifest.json',
'flight-manifest.js',
'flight-manifest.json',
]
const requiredServerFiles = (
await fs.readJSON(join(distDir, 'required-server-files.json'))
).files
files.forEach((file) => {
const filepath = join(distServerDir, file)
expect(fs.existsSync(filepath)).toBe(true)
})
requiredServerFiles.forEach((file) => {
const requiredFilePath = join(appDir, file)
expect(fs.existsSync(requiredFilePath)).toBe(true)
})
})
}
},
}
*/
const nodejsRuntimeBasicSuite = {
runTests: (context, env) => {
const options = { runtime: 'nodejs', env }
const distDir = join(appDir, '.next')
rsc(context, options)
if (env === 'prod') {
it('should generate edge SSR manifests for Node.js', async () => {
const distServerDir = join(distDir, 'server')
const requiredServerFiles = (
await fs.readJSON(join(distDir, 'required-server-files.json'))
).files
const files = [
'middleware-build-manifest.js',
'middleware-manifest.json',
'flight-manifest.json',
]
files.forEach((file) => {
const filepath = join(distServerDir, file)
expect(fs.existsSync(filepath)).toBe(true)
})
requiredServerFiles.forEach((file) => {
const requiredFilePath = join(appDir, file)
expect(fs.existsSync(requiredFilePath)).toBe(true)
})
})
}
},
}
const options = {
nodeArgs,
env: {
__NEXT_REACT_CHANNEL: 'exp',
},
}
// TODO: move these to test/e2e and use new test utils.
describe.skip('React Server Components', () => {
runDevSuite('Node.js runtime', appDir, nodejsRuntimeBasicSuite, options)
runProdSuite('Node.js runtime', appDir, nodejsRuntimeBasicSuite, options)
})
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