Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
55917c06
Unverified
Commit
55917c06
authored
Jan 10, 2024
by
Wyatt Johnson
Committed by
GitHub
Jan 10, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Transition some check calls in tests to retry (#60489)
Closes NEXT-2049
parent
26a2f603
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
80 additions
and
71 deletions
+80
-71
navigation.test.ts
test/e2e/app-dir/navigation/navigation.test.ts
+80
-71
No files found.
test/e2e/app-dir/navigation/navigation.test.ts
View file @
55917c06
import
{
createNextDescribe
}
from
'e2e-utils'
import
{
createNextDescribe
}
from
'e2e-utils'
import
{
check
,
retry
,
waitFor
}
from
'next-test-utils'
import
{
retry
,
waitFor
}
from
'next-test-utils'
import
type
{
Request
}
from
'playwright-chromium'
import
type
{
Request
}
from
'playwright-chromium'
createNextDescribe
(
createNextDescribe
(
...
@@ -17,9 +17,10 @@ createNextDescribe(
...
@@ -17,9 +17,10 @@ createNextDescribe(
browser
.
elementById
(
'set-query'
).
click
()
browser
.
elementById
(
'set-query'
).
click
()
await
check
(
await
retry
(()
=>
async
()
=>
await
browser
.
elementById
(
'query'
).
text
(),
expect
(
browser
.
elementById
(
'query'
).
text
()).
resolves
.
toEqual
(
'a=b&c=d'
'a=b&c=d'
)
)
)
const
url
=
new
URL
(
await
browser
.
url
())
const
url
=
new
URL
(
await
browser
.
url
())
...
@@ -27,32 +28,35 @@ createNextDescribe(
...
@@ -27,32 +28,35 @@ createNextDescribe(
})
})
it
(
'should handle unicode search params'
,
async
()
=>
{
it
(
'should handle unicode search params'
,
async
()
=>
{
const
requests
=
[]
const
requests
:
Array
<
{
pathname
:
string
ok
:
boolean
headers
:
Record
<
string
,
string
>
}
>
=
[]
const
browser
=
await
next
.
browser
(
'/search-params?name=名'
)
const
browser
=
await
next
.
browser
(
'/search-params?name=名'
)
browser
.
on
(
'request'
,
async
(
req
:
Request
)
=>
{
browser
.
on
(
'request'
,
async
(
req
:
Request
)
=>
{
const
res
=
await
req
.
response
()
const
res
=
await
req
.
response
()
requests
.
push
([
if
(
!
res
)
return
new
URL
(
req
.
url
()).
pathname
,
res
.
ok
(),
requests
.
push
({
await
res
.
headers
(),
pathname
:
new
URL
(
req
.
url
()).
pathname
,
])
ok
:
res
.
ok
(),
headers
:
res
.
headers
(),
})
})
})
expect
(
await
browser
.
elementById
(
'name'
).
text
()).
toBe
(
'名'
)
expect
(
await
browser
.
elementById
(
'name'
).
text
()).
toBe
(
'名'
)
await
browser
.
elementById
(
'link'
).
click
()
await
browser
.
elementById
(
'link'
).
click
()
await
check
(
async
()
=>
{
await
retry
(()
=>
return
requests
.
some
((
requestPair
)
=>
{
expect
(
requests
).
toContainEqual
({
const
[
pathname
,
ok
,
headers
]
=
requestPair
pathname
:
'/'
,
return
(
ok
:
true
,
pathname
===
'/'
&&
headers
:
expect
.
objectContaining
({
ok
&&
'content-type'
:
'text/x-component'
,
headers
[
'content-type'
]
===
'text/x-component'
}),
)
})
})
?
'success'
)
:
JSON
.
stringify
(
requests
)
},
'success'
)
})
})
it
(
'should not reset shallow url updates on prefetch'
,
async
()
=>
{
it
(
'should not reset shallow url updates on prefetch'
,
async
()
=>
{
...
@@ -142,15 +146,11 @@ createNextDescribe(
...
@@ -142,15 +146,11 @@ createNextDescribe(
expectedScroll
:
number
expectedScroll
:
number
)
=>
{
)
=>
{
await
browser
.
elementByCss
(
`#link-to-
${
val
.
toString
()}
`
).
click
()
await
browser
.
elementByCss
(
`#link-to-
${
val
.
toString
()}
`
).
click
()
await
check
(
async
()
=>
{
await
retry
(()
=>
const
val
=
await
browser
.
eval
(
'window.pageYOffset'
)
expect
(
browser
.
eval
(
'window.pageYOffset'
)).
resolves
.
toEqual
(
return
val
.
toString
()
expectedScroll
},
)
expectedScroll
.
toString
(),
true
,
// Try maximum of 15 seconds
15
)
)
}
}
...
@@ -184,15 +184,10 @@ createNextDescribe(
...
@@ -184,15 +184,10 @@ createNextDescribe(
expectedScroll
:
number
expectedScroll
:
number
)
=>
{
)
=>
{
await
browser
.
elementByCss
(
`#link-to-
${
val
.
toString
()}
`
).
click
()
await
browser
.
elementByCss
(
`#link-to-
${
val
.
toString
()}
`
).
click
()
await
check
(
await
retry
(()
=>
async
()
=>
{
expect
(
browser
.
eval
(
'window.pageYOffset'
)).
resolves
.
toEqual
(
const
val
=
await
browser
.
eval
(
'window.pageYOffset'
)
expectedScroll
return
val
.
toString
()
)
},
expectedScroll
.
toString
(),
true
,
// Try maximum of 15 seconds
15
)
)
}
}
...
@@ -215,15 +210,10 @@ createNextDescribe(
...
@@ -215,15 +210,10 @@ createNextDescribe(
expectedScroll
:
number
expectedScroll
:
number
)
=>
{
)
=>
{
await
browser
.
elementByCss
(
`#link-to-
${
val
.
toString
()}
`
).
click
()
await
browser
.
elementByCss
(
`#link-to-
${
val
.
toString
()}
`
).
click
()
await
check
(
await
retry
(()
=>
async
()
=>
{
expect
(
browser
.
eval
(
'window.pageYOffset'
)).
resolves
.
toEqual
(
const
val
=
await
browser
.
eval
(
'window.pageYOffset'
)
expectedScroll
return
val
.
toString
()
)
},
expectedScroll
.
toString
(),
true
,
// Try maximum of 15 seconds
15
)
)
}
}
...
@@ -242,15 +232,8 @@ createNextDescribe(
...
@@ -242,15 +232,8 @@ createNextDescribe(
// Wait for hash-link-back-to-same-page to load
// Wait for hash-link-back-to-same-page to load
.
waitForElementByCss
(
'#to-other-page'
)
.
waitForElementByCss
(
'#to-other-page'
)
await
check
(
await
retry
(()
=>
async
()
=>
{
expect
(
browser
.
eval
(
'window.pageYOffset'
)).
resolves
.
toEqual
(
0
)
const
val
=
await
browser
.
eval
(
'window.pageYOffset'
)
return
val
.
toString
()
},
(
0
).
toString
(),
true
,
// Try maximum of 15 seconds
15
)
)
})
})
})
})
...
@@ -262,49 +245,71 @@ createNextDescribe(
...
@@ -262,49 +245,71 @@ createNextDescribe(
const
browser
=
await
next
.
browser
(
pathname
)
const
browser
=
await
next
.
browser
(
pathname
)
await
browser
.
elementByCss
(
'#link-to-h1-hash-only'
).
click
()
await
browser
.
elementByCss
(
'#link-to-h1-hash-only'
).
click
()
await
check
(()
=>
browser
.
url
(),
next
.
url
+
pathname
+
'#h1'
)
await
retry
(()
=>
expect
(
browser
.
url
()).
resolves
.
toEqual
(
next
.
url
+
pathname
+
'#h1'
)
)
})
})
it
(
'should work with a hash-only `router.push(...)`'
,
async
()
=>
{
it
(
'should work with a hash-only `router.push(...)`'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
pathname
)
const
browser
=
await
next
.
browser
(
pathname
)
await
browser
.
elementByCss
(
'#button-to-h3-hash-only'
).
click
()
await
browser
.
elementByCss
(
'#button-to-h3-hash-only'
).
click
()
await
check
(()
=>
browser
.
url
(),
next
.
url
+
pathname
+
'#h3'
)
await
retry
(()
=>
expect
(
browser
.
url
()).
resolves
.
toEqual
(
next
.
url
+
pathname
+
'#h3'
)
)
})
})
it
(
'should work with a query-only href'
,
async
()
=>
{
it
(
'should work with a query-only href'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
pathname
)
const
browser
=
await
next
.
browser
(
pathname
)
await
browser
.
elementByCss
(
'#link-to-dummy-query'
).
click
()
await
browser
.
elementByCss
(
'#link-to-dummy-query'
).
click
()
await
check
(()
=>
browser
.
url
(),
next
.
url
+
pathname
+
'?foo=1&bar=2'
)
await
retry
(()
=>
expect
(
browser
.
url
()).
resolves
.
toEqual
(
next
.
url
+
pathname
+
'?foo=1&bar=2'
)
)
})
})
it
(
'should work with both relative hashes and queries'
,
async
()
=>
{
it
(
'should work with both relative hashes and queries'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
pathname
)
const
browser
=
await
next
.
browser
(
pathname
)
await
browser
.
elementByCss
(
'#link-to-h2-with-hash-and-query'
).
click
()
await
browser
.
elementByCss
(
'#link-to-h2-with-hash-and-query'
).
click
()
await
check
(()
=>
browser
.
url
(),
next
.
url
+
pathname
+
'?here=ok#h2'
)
await
retry
(()
=>
expect
(
browser
.
url
()).
resolves
.
toEqual
(
next
.
url
+
pathname
+
'?here=ok#h2'
)
)
// Only update hash
// Only update hash
await
browser
.
elementByCss
(
'#link-to-h1-hash-only'
).
click
()
await
browser
.
elementByCss
(
'#link-to-h1-hash-only'
).
click
()
await
check
(()
=>
browser
.
url
(),
next
.
url
+
pathname
+
'?here=ok#h1'
)
await
retry
(()
=>
expect
(
browser
.
url
()).
resolves
.
toEqual
(
next
.
url
+
pathname
+
'?here=ok#h1'
)
)
// Replace all with new query
// Replace all with new query
await
browser
.
elementByCss
(
'#link-to-dummy-query'
).
click
()
await
browser
.
elementByCss
(
'#link-to-dummy-query'
).
click
()
await
check
(()
=>
browser
.
url
(),
next
.
url
+
pathname
+
'?foo=1&bar=2'
)
await
retry
(()
=>
expect
(
browser
.
url
()).
resolves
.
toEqual
(
next
.
url
+
pathname
+
'?foo=1&bar=2'
)
)
// Add hash to existing query
// Add hash to existing query
await
browser
.
elementByCss
(
'#link-to-h1-hash-only'
).
click
()
await
browser
.
elementByCss
(
'#link-to-h1-hash-only'
).
click
()
await
check
(
await
retry
(()
=>
()
=>
browser
.
url
(),
expect
(
browser
.
url
()).
resolves
.
toEqual
(
next
.
url
+
pathname
+
'?foo=1&bar=2#h1'
next
.
url
+
pathname
+
'?foo=1&bar=2#h1'
)
)
)
// Update hash again via `router.push(...)`
// Update hash again via `router.push(...)`
await
browser
.
elementByCss
(
'#button-to-h3-hash-only'
).
click
()
await
browser
.
elementByCss
(
'#button-to-h3-hash-only'
).
click
()
await
check
(
await
retry
(()
=>
()
=>
browser
.
url
(),
expect
(
browser
.
url
()).
resolves
.
toEqual
(
next
.
url
+
pathname
+
'?foo=1&bar=2#h3'
next
.
url
+
pathname
+
'?foo=1&bar=2#h3'
)
)
)
})
})
})
})
...
@@ -581,7 +586,11 @@ createNextDescribe(
...
@@ -581,7 +586,11 @@ createNextDescribe(
.
elementByCss
(
'#link-to-pages-router'
)
.
elementByCss
(
'#link-to-pages-router'
)
.
click
()
.
click
()
.
waitForElementByCss
(
'#link-to-app'
)
.
waitForElementByCss
(
'#link-to-app'
)
await
check
(()
=>
browser
.
url
(),
next
.
url
+
'/some#non-existent'
)
await
retry
(()
=>
expect
(
browser
.
url
()).
resolves
.
toEqual
(
next
.
url
+
'/some#non-existent'
)
)
})
})
if
(
!
isNextDev
)
{
if
(
!
isNextDev
)
{
...
@@ -776,7 +785,7 @@ createNextDescribe(
...
@@ -776,7 +785,7 @@ createNextDescribe(
const
newScrollPosition
=
await
browser
.
eval
(
'window.pageYOffset'
)
const
newScrollPosition
=
await
browser
.
eval
(
'window.pageYOffset'
)
// confirm that the scroll position was restored
// confirm that the scroll position was restored
await
check
(()
=>
scrollPosition
===
newScrollPosition
,
true
)
expect
(
newScrollPosition
).
toEqual
(
scrollPosition
)
})
})
})
})
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment