Skip to content

Commit c053cbe

Browse files
committed
test: add test case for next/navigation#redirect
1 parent 19bf8b6 commit c053cbe

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { redirect } from 'next/navigation'
2+
3+
const Page = async () => {
4+
return redirect(`/app-redirect/dest`)
5+
}
6+
7+
export const generateStaticParams = async () => {
8+
return [{ slug: 'prerendered' }]
9+
}
10+
11+
export default Page
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default function Page() {
2+
return (
3+
<main>
4+
<h1>Hello next/navigation#redirect target</h1>
5+
</main>
6+
)
7+
}
8+
9+
export const dynamic = 'force-static'

tests/integration/simple-app.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,20 @@ test.skipIf(hasDefaultTurbopackBuilds())<FixtureTestContext>(
444444
expect(parsedBody.bundledCJSModule.isBundled).toEqual(true)
445445
},
446446
)
447+
for (const { slug, label } of [
448+
{ slug: 'prerendered', label: 'prerendered' },
449+
{ slug: 'non-prerendered', label: 'not prerendered' },
450+
]) {
451+
test<FixtureTestContext>(`app router page that uses next/navigation#redirect works when page is ${label}`, async (ctx) => {
452+
await createFixture('simple', ctx)
453+
await runPlugin(ctx)
454+
455+
const response = await invokeFunction(ctx, { url: `/app-redirect/${slug}` })
456+
457+
expect(response.statusCode).toBe(307)
458+
expect(response.headers['location']).toBe('/app-redirect/dest')
459+
})
460+
}
447461

448462
describe('next patching', async () => {
449463
const { cp: originalCp, appendFile } = (await vi.importActual(

0 commit comments

Comments
 (0)