Skip to content

Commit

Permalink
test: merge rsc custom app cases (vercel#36713)
Browse files Browse the repository at this point in the history
the rsc & streaming test app is too big to build which is time consuming, move custom _app cases to switchable runtime test suite
  • Loading branch information
huozhi authored May 5, 2022
1 parent 6f90d19 commit f6af0bc
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import fs from 'fs-extra'

import {
fetchViaHTTP,
renderViaHTTP,
nextBuild,
runDevSuite,
runProdSuite,
Expand All @@ -15,7 +14,6 @@ import {
appDir,
nativeModuleTestAppDir,
appPage,
appServerPage,
error500Page,
nextConfig,
} from './utils'
Expand All @@ -27,13 +25,6 @@ import basic from './basic'
import runtime from './runtime'
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 = `
import '../styles.css'
Expand Down Expand Up @@ -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 = {
runTests: css,
beforeAll: () => appPage.write(appWithGlobalCss),
Expand All @@ -208,8 +186,5 @@ runProdSuite('Node.js runtime', appDir, nodejsRuntimeBasicSuite)
runDevSuite('Edge runtime', appDir, edgeRuntimeBasicSuite)
runProdSuite('Edge runtime', appDir, edgeRuntimeBasicSuite)

runDevSuite('Custom App', appDir, customAppPageSuite)
runProdSuite('Custom App', appDir, customAppPageSuite)

runDevSuite('CSS', appDir, cssSuite)
runProdSuite('CSS', appDir, cssSuite)
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,48 @@ function splitLines(text) {
.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 }) {
const html1 = await renderViaHTTP(appPort, url)
const renderedAt1 = +html1.match(/Time: (\d+)/)[1]
Expand All @@ -44,9 +86,8 @@ async function testRoute(appPort, url, { isStatic, isEdge, isRSC }) {
const [rootClass, oppositeRootClass] = isRSC
? [rootClasses[0], rootClasses[1]]
: [rootClasses[1], rootClasses[0]]
const appServerOccurrence =
html1.match(new RegExp(`class="${rootClass}"`, 'g')) || []
expect(appServerOccurrence.length).toBe(1)

expect(getOccurrence(html1, new RegExp(`class="${rootClass}"`, 'g'))).toBe(1)
expect(html1).not.toContain(`"${oppositeRootClass}"`)
}

Expand All @@ -67,6 +108,8 @@ describe('Switchable runtime (prod)', () => {
await killApp(context.server)
})

flight(context)

it('should build /static as a static page with the nodejs runtime', async () => {
await testRoute(context.appPort, '/static', {
isStatic: true,
Expand Down Expand Up @@ -281,6 +324,7 @@ describe('Switchable runtime (dev)', () => {
await killApp(context.server)
})

flight(context)
it('should support client side navigation to ssr rsc pages', async () => {
let flightRequest = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const nativeModuleTestAppDir = join(
'../unsupported-native-module'
)
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 nextConfig = new File(join(appDir, 'next.config.js'))

Expand Down

0 comments on commit f6af0bc

Please sign in to comment.