Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for rewrite from pages to app with existing pages path #41023

Merged
merged 3 commits into from Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions test/e2e/app-dir/app/middleware.js
Expand Up @@ -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))
}
Expand Down
15 changes: 15 additions & 0 deletions 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 (
<>
<p>hello from exists but not routed {message}</p>
</>
)
}
11 changes: 11 additions & 0 deletions 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 (
<>
<Link href="/exists-but-not-routed">
<a id="link-to-rewritten-path">Exists but not routed</a>
</Link>
</>
)
}
23 changes: 22 additions & 1 deletion test/e2e/app-dir/index.test.ts
Expand Up @@ -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')

Expand Down