Files
vercel__next.js/test/e2e/app-dir/segment-cache/prefetch-auto/prefetch-auto.test.ts
Zack Tanner dd5e3ad611 [ci]: move router-act to top level testing utils (#84653)
We're starting to use this pattern in more places, so this moves `router-act` into our top level testing utils.
2025-10-08 17:01:40 -07:00

59 lines
1.6 KiB
TypeScript

import { nextTestSetup } from 'e2e-utils'
import type * as Playwright from 'playwright'
import { createRouterAct } from 'router-act'
describe('<Link prefetch="auto">', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
if (isNextDev) {
it('disabled in development / deployment', () => {})
return
}
// NOTE: Since "auto" is just an alias for the default, I'm not bothering to
// write tests for every default prefetching behavior; that's covered by a
// bunch of other test suites. This is just a quick test to confirm that the
// alias exists.
it('<Link prefetch="auto"> works the same as if prefetch were undefined or null', async () => {
// Test that the link only prefetches the static part of the target page
let page: Playwright.Page
const browser = await next.browser('/', {
beforePageLoad(p: Playwright.Page) {
page = p
},
})
const act = createRouterAct(page)
// Reveal the link to trigger a prefetch
await act(async () => {
const linkToggle = await browser.elementByCss(
'input[data-link-accordion="/dynamic"]'
)
await linkToggle.click()
}, [
// Should prefetch the loading boundary
{
includes: 'Loading...',
},
// Should not prefetch the dynamic content
{
includes: 'Dynamic content',
block: 'reject',
},
])
// Navigate to the page
await act(
async () => {
await browser.elementByCss('a[href="/dynamic"]').click()
},
{
// Now the dynamic content should be fetched
includes: 'Dynamic content',
}
)
})
})