diff --git a/test/e2e/app-dir/app/middleware.js b/test/e2e/app-dir/app/middleware.js index 458cfd5ffa323..1c0cb01aa16b3 100644 --- a/test/e2e/app-dir/app/middleware.js +++ b/test/e2e/app-dir/app/middleware.js @@ -6,6 +6,10 @@ import { NextResponse } from 'next/server' * @returns {NextResponse | undefined} */ export function middleware(request) { + if (request.nextUrl.pathname === '/exists-but-not-routed') { + return NextResponse.rewrite(new URL('/dashboard', request.url)) + } + if (request.nextUrl.pathname === '/middleware-to-dashboard') { return NextResponse.rewrite(new URL('/dashboard', request.url)) } diff --git a/test/e2e/app-dir/app/pages/exists-but-not-routed.js b/test/e2e/app-dir/app/pages/exists-but-not-routed.js new file mode 100644 index 0000000000000..56f482cef6f16 --- /dev/null +++ b/test/e2e/app-dir/app/pages/exists-but-not-routed.js @@ -0,0 +1,15 @@ +export async function getServerSideProps() { + return { + props: { + message: 'Hello World!', + }, + } +} + +export default function Page({ message }) { + return ( + <> +

hello from exists but not routed {message}

+ + ) +} diff --git a/test/e2e/app-dir/app/pages/link-to-rewritten-path.js b/test/e2e/app-dir/app/pages/link-to-rewritten-path.js new file mode 100644 index 0000000000000..177f41aa73e33 --- /dev/null +++ b/test/e2e/app-dir/app/pages/link-to-rewritten-path.js @@ -0,0 +1,11 @@ +import Link from 'next/link' + +export default function Page(props) { + return ( + <> + + Exists but not routed + + + ) +} diff --git a/test/e2e/app-dir/index.test.ts b/test/e2e/app-dir/index.test.ts index c67d345bb0d35..adaeb87ffae10 100644 --- a/test/e2e/app-dir/index.test.ts +++ b/test/e2e/app-dir/index.test.ts @@ -238,13 +238,34 @@ describe('app dir', () => { }) describe('rewrites', () => { - // TODO-APP: + // TODO-APP: rewrite url is broken it.skip('should support rewrites on initial load', async () => { const browser = await webdriver(next.url, '/rewritten-to-dashboard') expect(await browser.elementByCss('h1').text()).toBe('Dashboard') expect(await browser.url()).toBe(`${next.url}/rewritten-to-dashboard`) }) + it('should support rewrites on client-side navigation from pages to app with existing pages path', async () => { + const browser = await webdriver(next.url, '/link-to-rewritten-path') + + try { + // Click the link. + await browser.elementById('link-to-rewritten-path').click() + await browser.waitForElementByCss('#from-dashboard') + + // Check to see that we were rewritten and not redirected. + // TODO-APP: rewrite url is broken + // expect(await browser.url()).toBe(`${next.url}/rewritten-to-dashboard`) + + // Check to see that the page we navigated to is in fact the dashboard. + expect(await browser.elementByCss('#from-dashboard').text()).toBe( + 'hello from app/dashboard' + ) + } finally { + await browser.close() + } + }) + it('should support rewrites on client-side navigation', async () => { const browser = await webdriver(next.url, '/rewrites')