diff --git a/test/e2e/app-dir/app-prefetch/app/page.js b/test/e2e/app-dir/app-prefetch/app/page.js index ccded0f324b50..1f152de4f44cc 100644 --- a/test/e2e/app-dir/app-prefetch/app/page.js +++ b/test/e2e/app-dir/app-prefetch/app/page.js @@ -8,6 +8,9 @@ export default function HomePage() { To Static Page + + To Dynamic Page + To Dynamic Slug Page diff --git a/test/e2e/app-dir/app-prefetch/prefetching.test.ts b/test/e2e/app-dir/app-prefetch/prefetching.test.ts index 8ce13e2fc4b8f..c7c52dda7b4fd 100644 --- a/test/e2e/app-dir/app-prefetch/prefetching.test.ts +++ b/test/e2e/app-dir/app-prefetch/prefetching.test.ts @@ -308,9 +308,11 @@ describe('app dir - prefetching', () => { beforePageLoad(page: Page) { page.on('request', async (req: Request) => { const url = new URL(req.url()) - const headers = await req.allHeaders() - if (headers['rsc']) { - rscRequests.push(url.pathname) + if (url.pathname === '/static-page' || url.pathname === '/') { + const headers = await req.allHeaders() + if (headers['rsc']) { + rscRequests.push(url.pathname) + } } }) }, @@ -344,7 +346,9 @@ describe('app dir - prefetching', () => { // we should be on the static page await browser.waitForElementByCss('#static-page') - // We still shouldn't see any requests + await browser.waitForIdleNetwork() + + // We still shouldn't see any requests since it respects the static staletime (default 5m) await retry(async () => { expect(rscRequests.filter((req) => req === '/static-page').length).toBe( 0 @@ -358,9 +362,11 @@ describe('app dir - prefetching', () => { beforePageLoad(page: Page) { page.on('request', async (req: Request) => { const url = new URL(req.url()) - const headers = await req.allHeaders() - if (headers['rsc']) { - rscRequests.push(url.pathname) + if (url.pathname === '/dynamic-page' || url.pathname === '/') { + const headers = await req.allHeaders() + if (headers['rsc']) { + rscRequests.push(url.pathname) + } } }) }, @@ -381,6 +387,27 @@ describe('app dir - prefetching', () => { rscRequests.filter((req) => req === '/dynamic-page').length ).toBe(0) }) + + // navigate to index + await browser.elementByCss('[href="/"]').click() + + // we should be on the index page + await browser.waitForElementByCss('#to-dashboard') + + // navigate to the dynamic page + await browser.elementByCss('[href="/dynamic-page"]').click() + + // we should be on the dynamic page + await browser.waitForElementByCss('#dynamic-page') + + await browser.waitForIdleNetwork() + + // We should see a request for the dynamic page since it respects the dynamic staletime (default 0) + await retry(async () => { + expect( + rscRequests.filter((req) => req === '/dynamic-page').length + ).toBe(1) + }) }) })