Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update flakey middleware rewrite test #41007

Merged
merged 4 commits into from Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions test/e2e/middleware-general/test/index.test.ts
Expand Up @@ -212,10 +212,12 @@ describe('Middleware Runtime', () => {
})
await browser.eval('window.beforeNav = 1')

await check(() => {
return requests.some((req) =>
new URL(req, 'http://n').pathname.endsWith('/to-ssg.json')
)
await check(async () => {
const didReq = await browser.eval('next.router.isReady')
return didReq ||
requests.some((req) =>
new URL(req, 'http://n').pathname.endsWith('/to-ssg.json')
)
? 'found'
: JSON.stringify(requests)
}, 'found')
Expand Down
33 changes: 12 additions & 21 deletions test/e2e/middleware-rewrites/test/index.test.ts
Expand Up @@ -401,7 +401,6 @@ describe('Middleware Rewrite', () => {
).toEqual({ hello: 'world' })
expect(await browser.eval('location.pathname')).toBe('/about')
expect(await browser.eval('location.search')).toBe('?hello=world')
expect(requests).toEqual([])

await browser.eval(
`next.router.push('/about', undefined, { shallow: true })`
Expand All @@ -417,7 +416,6 @@ describe('Middleware Rewrite', () => {
).toEqual({})
expect(await browser.eval('location.pathname')).toBe('/about')
expect(await browser.eval('location.search')).toBe('')
expect(requests).toEqual([])
})

it('should handle shallow navigation correctly (dynamic page)', async () => {
Expand All @@ -432,8 +430,9 @@ describe('Middleware Rewrite', () => {
})

// wait for initial query update request
await check(() => {
if (requests.length > 0) {
await check(async () => {
const didReq = await browser.eval('next.router.isReady')
if (didReq || requests.length > 0) {
requests = []
return 'yup'
}
Expand All @@ -454,7 +453,6 @@ describe('Middleware Rewrite', () => {
'/fallback-true-blog/first'
)
expect(await browser.eval('location.search')).toBe('?hello=world')
expect(requests).toEqual([])

await browser.eval(
`next.router.push('/fallback-true-blog/second', undefined, { shallow: true })`
Expand All @@ -473,7 +471,6 @@ describe('Middleware Rewrite', () => {
'/fallback-true-blog/second'
)
expect(await browser.eval('location.search')).toBe('')
expect(requests).toEqual([])
})

it('should resolve dynamic route after rewrite correctly', async () => {
Expand All @@ -493,8 +490,9 @@ describe('Middleware Rewrite', () => {
})

// wait for initial query update request
await check(() => {
if (requests.length > 0) {
await check(async () => {
const didReq = await browser.eval('next.router.isReady')
if (requests.length > 0 || didReq) {
requests = []
return 'yup'
}
Expand All @@ -512,7 +510,6 @@ describe('Middleware Rewrite', () => {
'/fallback-true-blog/first'
)
expect(await browser.eval('location.search')).toBe('')
expect(requests).toEqual([])

await browser.eval(`next.router.push('/fallback-true-blog/rewritten')`)
await check(
Expand All @@ -528,9 +525,12 @@ describe('Middleware Rewrite', () => {
'/fallback-true-blog/rewritten'
)
expect(await browser.eval('location.search')).toBe('')
expect(requests).toEqual([
`/_next/data/BUILD_ID/en/fallback-true-blog/rewritten.json`,
])
expect(
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 check(
Expand All @@ -550,15 +550,6 @@ describe('Middleware Rewrite', () => {
'/fallback-true-blog/second'
)
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([])
})
}

Expand Down