Add a failing test

parent 893d59f9
export default async function Page({
params,
}: {
params: Promise<{ lang: string; slug: string }>
}) {
const { slug } = await params
return <p>slug: {slug}</p>
}
export function generateStaticParams({ params }: { params: { lang: string } }) {
return params.lang === 'fr' ? [{ slug: '1' }] : []
}
import { ReactNode } from 'react'
import { setTimeout } from 'timers/promises'
export default async function LangLayout({
children,
params,
}: {
children: ReactNode
params: Promise<{ lang: string }>
}) {
const { lang } = await params
if (lang === 'en') {
// Simulate uncached I/O. This should lead to a build-time error, because we
// expect a fallback shell to be generated for /en/[slug]. It would be a
// prerender error at runtime if we tried to generate a route shell at
// runtime for /en/foo instead.
await setTimeout(100)
}
return (
<>
<h1>lang: {lang}</h1>
<main>{children}</main>
</>
)
}
export function generateStaticParams() {
return [{ lang: 'en' }, { lang: 'fr' }]
}
import { ReactNode } from 'react'
export default function Root({ children }: { children: ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
experimental: {
dynamicIO: true,
},
}
module.exports = nextConfig
import { isNextDev, nextTestSetup } from 'e2e-utils'
describe('sub-shell-generation', () => {
const { next, isNextStart } = nextTestSetup({
files: __dirname,
skipStart: !isNextDev,
})
if (isNextStart) {
it('should fail with a validation error at build time', async () => {
await expect(next.build()).toReject()
})
}
it('should not fail when requesting /en/foo', async () => {
if (isNextStart) {
try {
await next.start()
} catch {
// Ignoring for now, until the build actually fails, in which case this
// whole test will be obsolete, and the test above will be sufficient.
}
}
const res = await next.fetch('/en/foo')
expect(res.status).toBe(200)
})
})
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