Unverified Commit e15549c7 authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

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)
parent 49377880
...@@ -12,7 +12,10 @@ describe('prefetch-navigation', () => { ...@@ -12,7 +12,10 @@ describe('prefetch-navigation', () => {
} }
it('should render the prefetch without waiting for the RSC request', async () => { it('should render the prefetch without waiting for the RSC request', async () => {
const rscRequestPromise = new Map<string, any>() const rscRequestPromise = new Map<
string,
{ resolve: () => Promise<void> }
>()
const browser = await next.browser('/catch-all/1', { const browser = await next.browser('/catch-all/1', {
beforePageLoad(page: Page) { beforePageLoad(page: Page) {
page.route('**/catch-all/**', async (route: Route) => { page.route('**/catch-all/**', async (route: Route) => {
...@@ -23,20 +26,26 @@ describe('prefetch-navigation', () => { ...@@ -23,20 +26,26 @@ describe('prefetch-navigation', () => {
if (headers['rsc'] === '1' && !headers['next-router-prefetch']) { if (headers['rsc'] === '1' && !headers['next-router-prefetch']) {
// Create a promise that will be resolved by the later test code // Create a promise that will be resolved by the later test code
let resolve: () => void let resolvePromise: () => void
const promise = new Promise<void>((res) => (resolve = res)) const promise = new Promise<void>((res) => {
resolvePromise = res
})
if (rscRequestPromise.has(pathname)) { if (rscRequestPromise.has(pathname)) {
throw new Error('Duplicate request') 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 the promise to effectively stall the request
await promise await promise
// Continue the route after resolving the promise
await route.continue()
} else { } else {
await route.continue() await route.continue()
} }
......
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