-
Notifications
You must be signed in to change notification settings - Fork 27.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic navigation test for Segment Cache
Almost nothing in the Segment Cache is implemented yet — all navigations result in a cache miss. This just confirms that when a cache miss occurs, it successfully navigates to the next page.
- Loading branch information
Showing
8 changed files
with
113 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode | ||
}) { | ||
return ( | ||
<html lang="en"> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
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,5 @@ | ||
import Link from 'next/link' | ||
|
||
export default function Page() { | ||
return <Link href="/test">Go to test page</Link> | ||
} |
26 changes: 26 additions & 0 deletions
26
test/e2e/app-dir/segment-cache/basic/app/streaming-text.tsx
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,26 @@ | ||
import { Suspense } from 'react' | ||
import { connection } from 'next/server' | ||
|
||
async function DynamicText({ text }) { | ||
await connection() | ||
return text | ||
} | ||
|
||
export function StreamingText({ | ||
static: staticText, | ||
dynamic, | ||
}: { | ||
static: string | ||
dynamic: string | ||
}) { | ||
return ( | ||
<div data-streaming-text> | ||
<div>{staticText}</div> | ||
<div> | ||
<Suspense fallback={`Loading... [${dynamic}]`}> | ||
<DynamicText text={dynamic} /> | ||
</Suspense> | ||
</div> | ||
</div> | ||
) | ||
} |
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 { StreamingText } from '../../streaming-text' | ||
|
||
export default function Page() { | ||
return ( | ||
<div id="nav"> | ||
<StreamingText static="Static in nav" dynamic="Dynamic in nav" /> | ||
</div> | ||
) | ||
} |
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 { StreamingText } from '../streaming-text' | ||
|
||
export default function Layout({ | ||
nav, | ||
children, | ||
}: { | ||
nav: React.ReactNode | ||
children: React.ReactNode | ||
}) { | ||
return ( | ||
<> | ||
<StreamingText static="Static in layout" dynamic="Dynamic in layout" /> | ||
<div>{nav}</div> | ||
<div>{children}</div> | ||
</> | ||
) | ||
} |
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,5 @@ | ||
import { StreamingText } from '../streaming-text' | ||
|
||
export default function Page() { | ||
return <StreamingText static="Static in page" dynamic="Dynamic in page" /> | ||
} |
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,12 @@ | ||
/** | ||
* @type {import('next').NextConfig} | ||
*/ | ||
const nextConfig = { | ||
experimental: { | ||
ppr: true, | ||
dynamicIO: true, | ||
clientSegmentCache: true, | ||
}, | ||
} | ||
|
||
module.exports = nextConfig |
28 changes: 28 additions & 0 deletions
28
test/e2e/app-dir/segment-cache/basic/segment-cache-basic.test.ts
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,28 @@ | ||
import { nextTestSetup } from 'e2e-utils' | ||
|
||
describe('segment cache (basic tests)', () => { | ||
const { next, isNextDev, skipped } = nextTestSetup({ | ||
files: __dirname, | ||
skipDeployment: true, | ||
}) | ||
if (isNextDev || skipped) { | ||
test('ppr is disabled', () => {}) | ||
return | ||
} | ||
|
||
it('basic navigation', async () => { | ||
const browser = await next.browser('/') | ||
|
||
// Navigate to the test page | ||
const link = await browser.elementByCss('a') | ||
await link.click() | ||
|
||
// Confirm that the content has streamed in and the URL has updated | ||
// as expected | ||
const nav = await browser.elementById('nav') | ||
expect(await nav.innerHTML()).toMatchInlineSnapshot( | ||
`"<div data-streaming-text="true"><div>Static in nav</div><div>Dynamic in nav</div></div>"` | ||
) | ||
expect(new URL(await browser.url()).pathname).toBe('/test') | ||
}) | ||
}) |