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