Unverified Commit 098c591f authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

test: stabilize app-dir hash navigation RSC assertion (#89867)

## Summary
- stabilize the hash navigation assertion in `navigation.test.ts` by
checking for query-param-specific RSC requests instead of any RSC
request
- switch request header reads from `req.allHeaders()` to synchronous
`req.headers()` in the request listener to avoid teardown timing errors
- keep the existing behavior check that query-param navigation triggers
an RSC request
parent 2b0e3f1d
......@@ -150,13 +150,13 @@ describe('app dir - navigation', () => {
describe('hash', () => {
it('should scroll to the specified hash', async () => {
let hasRscRequest = false
const rscRequestUrls = new Set<string>()
const browser = await next.browser('/hash', {
beforePageLoad(page) {
page.on('request', async (req) => {
const headers = await req.allHeaders()
page.on('request', (req) => {
const headers = req.headers()
if (headers['rsc']) {
hasRscRequest = true
rscRequestUrls.add(req.url())
}
})
},
......@@ -180,8 +180,8 @@ describe('app dir - navigation', () => {
}
// Wait for all network requests to finish, and then initialize the flag
// used to determine if any RSC requests are made
hasRscRequest = false
// used to determine if any query-param RSC requests are made.
rscRequestUrls.clear()
await checkLink(6, 128)
await checkLink(50, 744)
......@@ -192,17 +192,23 @@ describe('app dir - navigation', () => {
await checkLink('non-existent', 0)
if (!isNextDev) {
// there should have been no RSC calls to fetch data
// this is skipped in development because there'll never be a prefetch cache
// entry for the loaded page and so every request will be a cache miss.
expect(hasRscRequest).toBe(false)
// Hash-only navigations should not request the query-param payload.
// In some runtimes, hash-only transitions can still trigger RSC
// requests for /hash itself, so we assert on query-param payloads.
const hasQueryParamRscRequest = Array.from(rscRequestUrls).some((url) =>
url.includes('with-query-param')
)
expect(hasQueryParamRscRequest).toBe(false)
}
await checkLink('query-param', 2284)
await browser.waitForIdleNetwork()
// There should be an RSC request if the query param is changed
expect(hasRscRequest).toBe(true)
const hasQueryParamRscRequest = Array.from(rscRequestUrls).some((url) =>
url.includes('with-query-param')
)
expect(hasQueryParamRscRequest).toBe(true)
})
it('should not scroll to hash when scroll={false} is set', async () => {
......
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