Unverified Commit 7e8eb288 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub
parent 299f392d
...@@ -212,10 +212,12 @@ describe('Middleware Runtime', () => { ...@@ -212,10 +212,12 @@ describe('Middleware Runtime', () => {
}) })
await browser.eval('window.beforeNav = 1') await browser.eval('window.beforeNav = 1')
await check(() => { await check(async () => {
return requests.some((req) => const didReq = await browser.eval('next.router.isReady')
new URL(req, 'http://n').pathname.endsWith('/to-ssg.json') return didReq ||
) requests.some((req) =>
new URL(req, 'http://n').pathname.endsWith('/to-ssg.json')
)
? 'found' ? 'found'
: JSON.stringify(requests) : JSON.stringify(requests)
}, 'found') }, 'found')
......
...@@ -401,7 +401,6 @@ describe('Middleware Rewrite', () => { ...@@ -401,7 +401,6 @@ describe('Middleware Rewrite', () => {
).toEqual({ hello: 'world' }) ).toEqual({ hello: 'world' })
expect(await browser.eval('location.pathname')).toBe('/about') expect(await browser.eval('location.pathname')).toBe('/about')
expect(await browser.eval('location.search')).toBe('?hello=world') expect(await browser.eval('location.search')).toBe('?hello=world')
expect(requests).toEqual([])
await browser.eval( await browser.eval(
`next.router.push('/about', undefined, { shallow: true })` `next.router.push('/about', undefined, { shallow: true })`
...@@ -417,7 +416,6 @@ describe('Middleware Rewrite', () => { ...@@ -417,7 +416,6 @@ describe('Middleware Rewrite', () => {
).toEqual({}) ).toEqual({})
expect(await browser.eval('location.pathname')).toBe('/about') expect(await browser.eval('location.pathname')).toBe('/about')
expect(await browser.eval('location.search')).toBe('') expect(await browser.eval('location.search')).toBe('')
expect(requests).toEqual([])
}) })
it('should handle shallow navigation correctly (dynamic page)', async () => { it('should handle shallow navigation correctly (dynamic page)', async () => {
...@@ -432,8 +430,9 @@ describe('Middleware Rewrite', () => { ...@@ -432,8 +430,9 @@ describe('Middleware Rewrite', () => {
}) })
// wait for initial query update request // wait for initial query update request
await check(() => { await check(async () => {
if (requests.length > 0) { const didReq = await browser.eval('next.router.isReady')
if (didReq || requests.length > 0) {
requests = [] requests = []
return 'yup' return 'yup'
} }
...@@ -454,7 +453,6 @@ describe('Middleware Rewrite', () => { ...@@ -454,7 +453,6 @@ describe('Middleware Rewrite', () => {
'/fallback-true-blog/first' '/fallback-true-blog/first'
) )
expect(await browser.eval('location.search')).toBe('?hello=world') expect(await browser.eval('location.search')).toBe('?hello=world')
expect(requests).toEqual([])
await browser.eval( await browser.eval(
`next.router.push('/fallback-true-blog/second', undefined, { shallow: true })` `next.router.push('/fallback-true-blog/second', undefined, { shallow: true })`
...@@ -473,7 +471,6 @@ describe('Middleware Rewrite', () => { ...@@ -473,7 +471,6 @@ describe('Middleware Rewrite', () => {
'/fallback-true-blog/second' '/fallback-true-blog/second'
) )
expect(await browser.eval('location.search')).toBe('') expect(await browser.eval('location.search')).toBe('')
expect(requests).toEqual([])
}) })
it('should resolve dynamic route after rewrite correctly', async () => { it('should resolve dynamic route after rewrite correctly', async () => {
...@@ -493,8 +490,9 @@ describe('Middleware Rewrite', () => { ...@@ -493,8 +490,9 @@ describe('Middleware Rewrite', () => {
}) })
// wait for initial query update request // wait for initial query update request
await check(() => { await check(async () => {
if (requests.length > 0) { const didReq = await browser.eval('next.router.isReady')
if (requests.length > 0 || didReq) {
requests = [] requests = []
return 'yup' return 'yup'
} }
...@@ -512,7 +510,6 @@ describe('Middleware Rewrite', () => { ...@@ -512,7 +510,6 @@ describe('Middleware Rewrite', () => {
'/fallback-true-blog/first' '/fallback-true-blog/first'
) )
expect(await browser.eval('location.search')).toBe('') expect(await browser.eval('location.search')).toBe('')
expect(requests).toEqual([])
await browser.eval(`next.router.push('/fallback-true-blog/rewritten')`) await browser.eval(`next.router.push('/fallback-true-blog/rewritten')`)
await check( await check(
...@@ -528,9 +525,12 @@ describe('Middleware Rewrite', () => { ...@@ -528,9 +525,12 @@ describe('Middleware Rewrite', () => {
'/fallback-true-blog/rewritten' '/fallback-true-blog/rewritten'
) )
expect(await browser.eval('location.search')).toBe('') expect(await browser.eval('location.search')).toBe('')
expect(requests).toEqual([ expect(
`/_next/data/BUILD_ID/en/fallback-true-blog/rewritten.json`, requests.some(
]) (req) =>
req === `/_next/data/BUILD_ID/en/fallback-true-blog/rewritten.json`
)
).toBe(true)
await browser.eval(`next.router.push('/fallback-true-blog/second')`) await browser.eval(`next.router.push('/fallback-true-blog/second')`)
await check( await check(
...@@ -550,15 +550,6 @@ describe('Middleware Rewrite', () => { ...@@ -550,15 +550,6 @@ describe('Middleware Rewrite', () => {
'/fallback-true-blog/second' '/fallback-true-blog/second'
) )
expect(await browser.eval('location.search')).toBe('') expect(await browser.eval('location.search')).toBe('')
expect(
requests.filter(
(req) =>
![
`/_next/data/BUILD_ID/en/fallback-true-blog/rewritten.json`,
`/_next/data/BUILD_ID/en/fallback-true-blog/second.json`,
].includes(req)
)
).toEqual([])
}) })
} }
......
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