Unverified Commit 721eb615 authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[test] Speed up prefetching suite (#85417)

parent 6ea6270e
......@@ -14,8 +14,7 @@ export function generateStaticParams() {
export default function IdPage(props) {
const params = use(props.params)
const data = use(getData())
console.log(data)
use(getData())
if (params.id === '123') {
return (
......
......@@ -2,7 +2,6 @@ export default function Root({ children }) {
return (
<html>
<head>
<script src="https://cdn.tailwindcss.com?plugins=typography"></script>
<title>Hello World</title>
<script
dangerouslySetInnerHTML={{
......
......@@ -5,22 +5,16 @@ import Link from 'next/link'
export default function Layout({ children }: { children: React.ReactNode }) {
return (
<>
<nav className="bg-gray-800">
<ul className="flex">
<li className="mr-6">
<Link href="/prefetch-auto-route-groups">
<p className="text-white hover:text-gray-300">Dashboard</p>
</Link>
<nav style={{ border: '1px solid #1f2937' }}>
<ul style={{ display: 'flex' }}>
<li style={{ marginRight: '1.5rem' }}>
<Link href="/prefetch-auto-route-groups">Dashboard</Link>
</li>
<li className="mr-6">
<Link href="/prefetch-auto-route-groups/sub/foo">
<p className="text-white hover:text-gray-300">Foo</p>
</Link>
<li style={{ marginRight: '1.5rem' }}>
<Link href="/prefetch-auto-route-groups/sub/foo">Foo</Link>
</li>
<li className="mr-6">
<Link href="/prefetch-auto-route-groups/sub/bar">
<p className="text-white hover:text-gray-300">Bar</p>
</Link>
<li style={{ marginRight: '1.5rem' }}>
<Link href="/prefetch-auto-route-groups/sub/bar">Bar</Link>
</li>
</ul>
</nav>
......
import Link from 'next/link'
export const dynamic = 'force-dynamic'
function getData() {
const res = new Promise((resolve) => {
setTimeout(() => {
resolve({ message: 'Layout Data!' })
}, 2000)
}, 1000)
})
return res
}
......@@ -17,9 +15,6 @@ export default async function Layout({ children }) {
return (
<div>
<h1>Layout</h1>
<Link prefetch={undefined} href="/prefetch-auto/justputit">
Prefetch Link
</Link>
{children}
<h3>{JSON.stringify(result)}</h3>
</div>
......
......@@ -4,7 +4,7 @@ function getData() {
const res = new Promise((resolve) => {
setTimeout(() => {
resolve({ message: 'Page Data!' })
}, 2000)
}, 1000)
})
return res
}
......
......@@ -314,22 +314,20 @@ describe('app dir - prefetching', () => {
async () => {
const reveal = await browser.elementByCss('#accordion-to-dynamic-page')
await reveal.click()
await browser.waitForElementByCss('#to-dynamic-page')
return await browser.elementByCss('#to-dynamic-page')
return browser.elementByCss('#to-dynamic-page')
},
{ includes: 'Loading Prefetch Auto' }
)
// Click the link to navigate - should trigger dynamic data fetch
await act(
const loadingText = await act(
async () => {
await link.click()
await browser.waitForElementByCss('#loading-text')
const loadingText = await browser.elementByCss('#loading-text').text()
expect(loadingText).toBe('Loading Prefetch Auto')
return browser.elementByCss('#loading-text').text()
},
{ includes: 'prefetch-auto-page-data' }
)
expect(loadingText).toBe('Loading Prefetch Auto')
// Wait for final data to appear
await browser.waitForElementByCss('#prefetch-auto-page-data')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment