Unverified Commit 86625a58 authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

Synchronize full prefetch test

Co-authored-by: 's avatarWill Binns-Smith <755844+wbinnssmith@users.noreply.github.com>
parent a37e8bb1
...@@ -190,8 +190,28 @@ describe('searchparams-reuse-loading', () => { ...@@ -190,8 +190,28 @@ describe('searchparams-reuse-loading', () => {
}) })
let interceptRequests = false let interceptRequests = false
let id3FullPrefetchResponse: Promise<void> | undefined
const browser = await next.browser(path, { const browser = await next.browser(path, {
beforePageLoad(page) { beforePageLoad(page) {
page.on('response', (response) => {
const requestHeaders = response.request().headers()
const url = new URL(response.url())
const normalizedPath = url.pathname.replace(/\/someValue$/, '')
const expectedPath =
path === '/' ? '/search-params' : `${path}/search-params`
if (
requestHeaders['next-router-prefetch'] &&
normalizedPath === expectedPath &&
url.searchParams.get('id') === '3' &&
response.ok()
) {
id3FullPrefetchResponse = response.finished().then((error) => {
if (error) throw error
})
}
})
page.route( page.route(
(url) => { (url) => {
return url.pathname.includes('search-params') return url.pathname.includes('search-params')
...@@ -308,10 +328,15 @@ describe('searchparams-reuse-loading', () => { ...@@ -308,10 +328,15 @@ describe('searchparams-reuse-loading', () => {
// Dev mode doesn't perform full prefetches, so this test is conditional // Dev mode doesn't perform full prefetches, so this test is conditional
await browser.elementByCss(`[href='${path}']`).click() await browser.elementByCss(`[href='${path}']`).click()
// Wait for the full prefetch to finish before navigating. Otherwise a // Wait for this specific response rather than generic network idle.
// slow CI worker can click while the prefetch response is still in // The full prefetch can be scheduled after the page first becomes idle.
// flight and time out waiting for the destination to render. await retry(
await browser.waitForIdleNetwork() () => expect(id3FullPrefetchResponse).toBeDefined(),
30_000,
500,
'Waiting for id=3 full prefetch response'
)
await id3FullPrefetchResponse
await browser await browser
.elementByCss(`[href="${searchParamsPagePath}?id=3"]`) .elementByCss(`[href="${searchParamsPagePath}?id=3"]`)
......
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