Skip to content

Commit d8090ff

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

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ test<FixtureTestContext>('Test that the simple next app is working', async (ctx)
108108
shouldHaveAppRouterNotFoundInPrerenderManifest() ? '/_not-found' : undefined,
109109
'/api/cached-permanent',
110110
'/api/cached-revalidate',
111+
'/app-redirect/dest',
112+
'/app-redirect/prerendered',
111113
'/config-redirect',
112114
'/config-redirect/dest',
113115
'/config-rewrite',
@@ -444,6 +446,20 @@ test.skipIf(hasDefaultTurbopackBuilds())<FixtureTestContext>(
444446
expect(parsedBody.bundledCJSModule.isBundled).toEqual(true)
445447
},
446448
)
449+
for (const { slug, label } of [
450+
{ slug: 'prerendered', label: 'prerendered' },
451+
{ slug: 'non-prerendered', label: 'not prerendered' },
452+
]) {
453+
test<FixtureTestContext>(`app router page that uses next/navigation#redirect works when page is ${label}`, async (ctx) => {
454+
await createFixture('simple', ctx)
455+
await runPlugin(ctx)
456+
457+
const response = await invokeFunction(ctx, { url: `/app-redirect/${slug}` })
458+
459+
expect(response.statusCode).toBe(307)
460+
expect(response.headers['location']).toBe('/app-redirect/dest')
461+
})
462+
}
447463

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

0 commit comments

Comments
 (0)