From e15549c70bb2e275c1d615ff425871a2341951c5 Mon Sep 17 00:00:00 2001 From: Zack Tanner <1939140+ztanner@users.noreply.github.com> Date: Wed, 10 Jul 2024 06:59:15 -0700 Subject: [PATCH] fix prefetch-navigation deploy test (#67616) This ensures that the route is fulfilled before resolving the promise used in the test, to make sure we don't proceed until the network finishes. [x-ref](https://github.com/vercel/next.js/actions/runs/9865629712/job/27243698469) --- .../prefetch-navigation.test.ts | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/test/e2e/app-dir/ppr-navigations/prefetch-navigation/prefetch-navigation.test.ts b/test/e2e/app-dir/ppr-navigations/prefetch-navigation/prefetch-navigation.test.ts index 1a6368ae79b21..5524ab1e65b19 100644 --- a/test/e2e/app-dir/ppr-navigations/prefetch-navigation/prefetch-navigation.test.ts +++ b/test/e2e/app-dir/ppr-navigations/prefetch-navigation/prefetch-navigation.test.ts @@ -12,7 +12,10 @@ describe('prefetch-navigation', () => { } it('should render the prefetch without waiting for the RSC request', async () => { - const rscRequestPromise = new Map() + const rscRequestPromise = new Map< + string, + { resolve: () => Promise } + >() const browser = await next.browser('/catch-all/1', { beforePageLoad(page: Page) { page.route('**/catch-all/**', async (route: Route) => { @@ -23,20 +26,26 @@ describe('prefetch-navigation', () => { if (headers['rsc'] === '1' && !headers['next-router-prefetch']) { // Create a promise that will be resolved by the later test code - let resolve: () => void - const promise = new Promise((res) => (resolve = res)) + let resolvePromise: () => void + const promise = new Promise((res) => { + resolvePromise = res + }) if (rscRequestPromise.has(pathname)) { throw new Error('Duplicate request') } - rscRequestPromise.set(pathname, { route, resolve }) + rscRequestPromise.set(pathname, { + resolve: async () => { + await route.continue() + // wait a moment to ensure the response is received + await new Promise((res) => setTimeout(res, 500)) + resolvePromise() + }, + }) // Await the promise to effectively stall the request await promise - - // Continue the route after resolving the promise - await route.continue() } else { await route.continue() }