Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test: added some test cases for new client side router * tests: added additional test cases * test: improved test support * feat: added support for `<Link soft />` * tests: improved test reliability * tests: added more cases for catch-all routes * tests: added app -> pages -> app tests * tests: add tests for useCookies + useHeaders * tests: added tests for usePreviewData * tests: added more tests for hooks and client components * tests: added tests for query/params handling * tests: fix tests for param/query to use props * tests: added some skipped tests for unimplemented features * tests: linting * refactor: updated TODO -> TODO-APP * tests: added some more test cases * tests: skipped failing test
- Loading branch information
Showing
39 changed files
with
990 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
test/e2e/app-dir/app/app/catch-all/[...slug]/page.server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export function getServerSideProps({ params }) { | ||
return { props: { params } } | ||
} | ||
|
||
export default function Page({ params }) { | ||
return ( | ||
<h1 id="text" data-params={params.slug.join('/') ?? ''}> | ||
hello from /catch-all/{params.slug.join('/')} | ||
</h1> | ||
) | ||
} |
7 changes: 7 additions & 0 deletions
7
test/e2e/app-dir/app/app/client-with-errors/get-server-side-props/page.client.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export function getServerSideProps() { | ||
return { props: {} } | ||
} | ||
|
||
export default function Page() { | ||
return null | ||
} |
7 changes: 7 additions & 0 deletions
7
test/e2e/app-dir/app/app/client-with-errors/get-static-props/page.client.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export function getStaticProps() { | ||
return { props: {} } | ||
} | ||
|
||
export default function Page() { | ||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
test/e2e/app-dir/app/app/hooks/use-cookies/client/page.client.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { useCookies } from 'next/dist/client/components/hooks-server' | ||
|
||
export default function Page() { | ||
// This should throw an error. | ||
useCookies() | ||
|
||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useCookies } from 'next/dist/client/components/hooks-server' | ||
|
||
export default function Page() { | ||
const cookies = useCookies() | ||
|
||
const hasCookie = | ||
'use-cookies' in cookies && cookies['use-cookies'] === 'value' | ||
|
||
return ( | ||
<> | ||
<h1 id="text">hello from /hooks/use-cookies</h1> | ||
{hasCookie ? ( | ||
<h2 id="has-cookie">Has use-cookies cookie</h2> | ||
) : ( | ||
<h2 id="does-not-have-cookie">Does not have use-cookies cookie</h2> | ||
)} | ||
</> | ||
) | ||
} |
8 changes: 8 additions & 0 deletions
8
test/e2e/app-dir/app/app/hooks/use-headers/client/page.client.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { useHeaders } from 'next/dist/client/components/hooks-server' | ||
|
||
export default function Page() { | ||
// This should throw an error. | ||
useHeaders() | ||
|
||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { useHeaders } from 'next/dist/client/components/hooks-server' | ||
|
||
export default function Page() { | ||
const headers = useHeaders() | ||
|
||
const hasHeader = | ||
'x-use-headers' in headers && headers['x-use-headers'] === 'value' | ||
|
||
return ( | ||
<> | ||
<h1 id="text">hello from /hooks/use-headers</h1> | ||
{hasHeader ? ( | ||
<h2 id="has-header">Has x-use-headers header</h2> | ||
) : ( | ||
<h2 id="does-not-have-header">Does not have x-use-headers header</h2> | ||
)} | ||
{'referer' in headers && headers['referer'] && ( | ||
<h3 id="has-referer">Has referer header</h3> | ||
)} | ||
</> | ||
) | ||
} |
8 changes: 8 additions & 0 deletions
8
test/e2e/app-dir/app/app/hooks/use-layout-segments/server/page.server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { useLayoutSegments } from 'next/dist/client/components/hooks-client' | ||
|
||
export default function Page() { | ||
// This should throw an error. | ||
useLayoutSegments() | ||
|
||
return null | ||
} |
8 changes: 8 additions & 0 deletions
8
test/e2e/app-dir/app/app/hooks/use-params/server/page.server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { useParams } from 'next/dist/client/components/hooks-client' | ||
|
||
export default function Page() { | ||
// This should throw an error. | ||
useParams() | ||
|
||
return null | ||
} |
13 changes: 13 additions & 0 deletions
13
test/e2e/app-dir/app/app/hooks/use-pathname/page.client.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { usePathname } from 'next/dist/client/components/hooks-client' | ||
|
||
export default function Page() { | ||
const pathname = usePathname() | ||
|
||
return ( | ||
<> | ||
<h1 id="pathname" data-pathname={pathname}> | ||
hello from /hooks/use-pathname | ||
</h1> | ||
</> | ||
) | ||
} |
8 changes: 8 additions & 0 deletions
8
test/e2e/app-dir/app/app/hooks/use-pathname/server/page.server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { usePathname } from 'next/dist/client/components/hooks-client' | ||
|
||
export default function Page() { | ||
// This should throw an error. | ||
usePathname() | ||
|
||
return null | ||
} |
8 changes: 8 additions & 0 deletions
8
test/e2e/app-dir/app/app/hooks/use-preview-data/client/page.client.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { usePreviewData } from 'next/dist/client/components/hooks-server' | ||
|
||
export default function Page() { | ||
// This should throw an error. | ||
usePreviewData() | ||
|
||
return null | ||
} |
18 changes: 18 additions & 0 deletions
18
test/e2e/app-dir/app/app/hooks/use-preview-data/page.server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { usePreviewData } from 'next/dist/client/components/hooks-server' | ||
|
||
export default function Page() { | ||
const data = usePreviewData() | ||
|
||
const hasData = !!data && data.key === 'value' | ||
|
||
return ( | ||
<> | ||
<h1>hello from /hooks/use-preview-data</h1> | ||
{hasData ? ( | ||
<h2 id="has-preview-data">Has preview data</h2> | ||
) : ( | ||
<h2 id="does-not-have-preview-data">Does not have preview data</h2> | ||
)} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { useRouter } from 'next/dist/client/components/hooks-client' | ||
|
||
export default function Page() { | ||
const router = useRouter() | ||
|
||
return ( | ||
<> | ||
<h1 id="router">hello from /hooks/use-router</h1> | ||
<button | ||
id="button-push" | ||
onClick={() => router.push('/hooks/use-router/sub-page')} | ||
> | ||
Router Push | ||
</button> | ||
</> | ||
) | ||
} |
8 changes: 8 additions & 0 deletions
8
test/e2e/app-dir/app/app/hooks/use-router/server/page.server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { useRouter } from 'next/dist/client/components/hooks-client' | ||
|
||
export default function Page() { | ||
// This should throw an error. | ||
useRouter() | ||
|
||
return null | ||
} |
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/app/app/hooks/use-router/sub-page/page.client.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Page() { | ||
return <h1 id="router-sub-page">hello from /hooks/use-router/sub-page</h1> | ||
} |
19 changes: 19 additions & 0 deletions
19
test/e2e/app-dir/app/app/hooks/use-search-params/page.client.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useSearchParams } from 'next/dist/client/components/hooks-client' | ||
|
||
export default function Page() { | ||
const params = useSearchParams() | ||
|
||
return ( | ||
<> | ||
<h1 | ||
id="params" | ||
data-param-first={params.first ?? 'N/A'} | ||
data-param-second={params.second ?? 'N/A'} | ||
data-param-third={params.third ?? 'N/A'} | ||
data-param-not-real={params.notReal ?? 'N/A'} | ||
> | ||
hello from /hooks/use-search-params | ||
</h1> | ||
</> | ||
) | ||
} |
8 changes: 8 additions & 0 deletions
8
test/e2e/app-dir/app/app/hooks/use-search-params/server/page.server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { useSearchParams } from 'next/dist/client/components/hooks-client' | ||
|
||
export default function Page() { | ||
// This should throw an error. | ||
useSearchParams() | ||
|
||
return null | ||
} |
8 changes: 8 additions & 0 deletions
8
test/e2e/app-dir/app/app/hooks/use-selected-layout-segment/server/page.server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { useSelectedLayoutSegment } from 'next/dist/client/components/hooks-client' | ||
|
||
export default function Page() { | ||
// This should throw an error. | ||
useSelectedLayoutSegment() | ||
|
||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Link from 'next/link' | ||
|
||
export default function Page() { | ||
return ( | ||
<Link href="/with-id"> | ||
<a id="link">With ID</a> | ||
</Link> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { nanoid } from 'nanoid' | ||
import Link from 'next/link' | ||
|
||
export default function Page() { | ||
return ( | ||
<> | ||
<h1 id="render-id">{nanoid()}</h1> | ||
<Link href="/link-hard-replace" replace> | ||
<a id="self-link">Self Link</a> | ||
</Link> | ||
<Link href="/link-hard-replace/subpage" replace> | ||
<a id="subpage-link">Subpage</a> | ||
</Link> | ||
</> | ||
) | ||
} |
9 changes: 9 additions & 0 deletions
9
test/e2e/app-dir/app/app/link-hard-replace/subpage/page.server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Link from 'next/link' | ||
|
||
export default function Page() { | ||
return ( | ||
<Link href="/link-hard-replace" replace> | ||
<a id="back-link">Self Link</a> | ||
</Link> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Link from 'next/link' | ||
|
||
export default function Page() { | ||
return ( | ||
<Link href="/with-id" soft> | ||
<a id="link">With ID</a> | ||
</Link> | ||
) | ||
} |
Oops, something went wrong.