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

test: merge rsc custom app cases (#36713)

the rsc & streaming test app is too big to build which is time consuming, move custom _app cases to switchable runtime test suite
parent 6f90d196
...@@ -5,7 +5,6 @@ import fs from 'fs-extra' ...@@ -5,7 +5,6 @@ import fs from 'fs-extra'
import { import {
fetchViaHTTP, fetchViaHTTP,
renderViaHTTP,
nextBuild, nextBuild,
runDevSuite, runDevSuite,
runProdSuite, runProdSuite,
...@@ -15,7 +14,6 @@ import { ...@@ -15,7 +14,6 @@ import {
appDir, appDir,
nativeModuleTestAppDir, nativeModuleTestAppDir,
appPage, appPage,
appServerPage,
error500Page, error500Page,
nextConfig, nextConfig,
} from './utils' } from './utils'
...@@ -27,13 +25,6 @@ import basic from './basic' ...@@ -27,13 +25,6 @@ import basic from './basic'
import runtime from './runtime' import runtime from './runtime'
import { getNodeBuiltinModuleNotSupportedInEdgeRuntimeMessage } from 'next/dist/build/utils' import { getNodeBuiltinModuleNotSupportedInEdgeRuntimeMessage } from 'next/dist/build/utils'
const rscAppPage = `
import Container from '../components/container.server'
export default function App({children}) {
return <Container>{children}</Container>
}
`
const appWithGlobalCss = ` const appWithGlobalCss = `
import '../styles.css' import '../styles.css'
...@@ -184,19 +175,6 @@ const nodejsRuntimeBasicSuite = { ...@@ -184,19 +175,6 @@ const nodejsRuntimeBasicSuite = {
}, },
} }
const customAppPageSuite = {
runTests: (context) => {
it('should render container in app', async () => {
const indexHtml = await renderViaHTTP(context.appPort, '/')
const indexFlight = await renderViaHTTP(context.appPort, '/?__flight__=1')
expect(indexHtml).toContain('container-server')
expect(indexFlight).toContain('container-server')
})
},
beforeAll: () => appServerPage.write(rscAppPage),
afterAll: () => appServerPage.delete(),
}
const cssSuite = { const cssSuite = {
runTests: css, runTests: css,
beforeAll: () => appPage.write(appWithGlobalCss), beforeAll: () => appPage.write(appWithGlobalCss),
...@@ -208,8 +186,5 @@ runProdSuite('Node.js runtime', appDir, nodejsRuntimeBasicSuite) ...@@ -208,8 +186,5 @@ runProdSuite('Node.js runtime', appDir, nodejsRuntimeBasicSuite)
runDevSuite('Edge runtime', appDir, edgeRuntimeBasicSuite) runDevSuite('Edge runtime', appDir, edgeRuntimeBasicSuite)
runProdSuite('Edge runtime', appDir, edgeRuntimeBasicSuite) runProdSuite('Edge runtime', appDir, edgeRuntimeBasicSuite)
runDevSuite('Custom App', appDir, customAppPageSuite)
runProdSuite('Custom App', appDir, customAppPageSuite)
runDevSuite('CSS', appDir, cssSuite) runDevSuite('CSS', appDir, cssSuite)
runProdSuite('CSS', appDir, cssSuite) runProdSuite('CSS', appDir, cssSuite)
...@@ -22,6 +22,48 @@ function splitLines(text) { ...@@ -22,6 +22,48 @@ function splitLines(text) {
.filter(Boolean) .filter(Boolean)
} }
function getOccurrence(text, matcher) {
return (text.match(matcher) || []).length
}
function flight(context) {
describe('flight response', () => {
it('should contain _app.server in flight response (node)', async () => {
const html = await renderViaHTTP(context.appPort, '/node-rsc')
const flightResponse = await renderViaHTTP(
context.appPort,
'/node-rsc?__flight__=1'
)
expect(
getOccurrence(html, new RegExp(`class="app-server-root"`, 'g'))
).toBe(1)
expect(
getOccurrence(
flightResponse,
new RegExp(`"className":\\s*"app-server-root"`, 'g')
)
).toBe(1)
})
})
it('should contain _app.server in flight response (edge)', async () => {
const html = await renderViaHTTP(context.appPort, '/edge-rsc')
const flightResponse = await renderViaHTTP(
context.appPort,
'/edge-rsc?__flight__=1'
)
expect(
getOccurrence(html, new RegExp(`class="app-server-root"`, 'g'))
).toBe(1)
expect(
getOccurrence(
flightResponse,
new RegExp(`"className":\\s*"app-server-root"`, 'g')
)
).toBe(1)
})
}
async function testRoute(appPort, url, { isStatic, isEdge, isRSC }) { async function testRoute(appPort, url, { isStatic, isEdge, isRSC }) {
const html1 = await renderViaHTTP(appPort, url) const html1 = await renderViaHTTP(appPort, url)
const renderedAt1 = +html1.match(/Time: (\d+)/)[1] const renderedAt1 = +html1.match(/Time: (\d+)/)[1]
...@@ -44,9 +86,8 @@ async function testRoute(appPort, url, { isStatic, isEdge, isRSC }) { ...@@ -44,9 +86,8 @@ async function testRoute(appPort, url, { isStatic, isEdge, isRSC }) {
const [rootClass, oppositeRootClass] = isRSC const [rootClass, oppositeRootClass] = isRSC
? [rootClasses[0], rootClasses[1]] ? [rootClasses[0], rootClasses[1]]
: [rootClasses[1], rootClasses[0]] : [rootClasses[1], rootClasses[0]]
const appServerOccurrence =
html1.match(new RegExp(`class="${rootClass}"`, 'g')) || [] expect(getOccurrence(html1, new RegExp(`class="${rootClass}"`, 'g'))).toBe(1)
expect(appServerOccurrence.length).toBe(1)
expect(html1).not.toContain(`"${oppositeRootClass}"`) expect(html1).not.toContain(`"${oppositeRootClass}"`)
} }
...@@ -67,6 +108,8 @@ describe('Switchable runtime (prod)', () => { ...@@ -67,6 +108,8 @@ describe('Switchable runtime (prod)', () => {
await killApp(context.server) await killApp(context.server)
}) })
flight(context)
it('should build /static as a static page with the nodejs runtime', async () => { it('should build /static as a static page with the nodejs runtime', async () => {
await testRoute(context.appPort, '/static', { await testRoute(context.appPort, '/static', {
isStatic: true, isStatic: true,
...@@ -281,6 +324,7 @@ describe('Switchable runtime (dev)', () => { ...@@ -281,6 +324,7 @@ describe('Switchable runtime (dev)', () => {
await killApp(context.server) await killApp(context.server)
}) })
flight(context)
it('should support client side navigation to ssr rsc pages', async () => { it('should support client side navigation to ssr rsc pages', async () => {
let flightRequest = null let flightRequest = null
......
...@@ -8,7 +8,6 @@ export const nativeModuleTestAppDir = join( ...@@ -8,7 +8,6 @@ export const nativeModuleTestAppDir = join(
'../unsupported-native-module' '../unsupported-native-module'
) )
export const appPage = new File(join(appDir, 'pages/_app.js')) export const appPage = new File(join(appDir, 'pages/_app.js'))
export const appServerPage = new File(join(appDir, 'pages/_app.server.js'))
export const error500Page = new File(join(appDir, 'pages/500.js')) export const error500Page = new File(join(appDir, 'pages/500.js'))
export const nextConfig = new File(join(appDir, 'next.config.js')) export const nextConfig = new File(join(appDir, 'next.config.js'))
......
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