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
12241384
Commit
12241384
authored
Dec 24, 2019
by
Joe Haddad
Committed by
JJ Kasper
Dec 24, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Chrome-Only Tests (#9825)
parent
69a34dd7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
72 deletions
+76
-72
index.test.js
test/integration/production/test/index.test.js
+76
-72
No files found.
test/integration/production/test/index.test.js
View file @
12241384
...
@@ -441,82 +441,86 @@ describe('Production Usage', () => {
...
@@ -441,82 +441,86 @@ describe('Production Usage', () => {
}
}
})
})
it
(
'should add prefetch tags when Link prefetch prop is used'
,
async
()
=>
{
if
(
browserName
===
'chrome'
)
{
const
browser
=
await
webdriver
(
appPort
,
'/prefetch'
)
it
(
'should add prefetch tags when Link prefetch prop is used'
,
async
()
=>
{
await
waitFor
(
2000
)
const
browser
=
await
webdriver
(
appPort
,
'/prefetch'
)
const
elements
=
await
browser
.
elementsByCss
(
'link[rel=prefetch]'
)
await
waitFor
(
2000
)
const
elements
=
await
browser
.
elementsByCss
(
'link[rel=prefetch]'
)
expect
(
elements
.
length
).
toBe
(
4
)
await
Promise
.
all
(
expect
(
elements
.
length
).
toBe
(
4
)
elements
.
map
(
async
element
=>
{
await
Promise
.
all
(
const
rel
=
await
element
.
getAttribute
(
'rel'
)
elements
.
map
(
async
element
=>
{
const
as
=
await
element
.
getAttribute
(
'as'
)
const
rel
=
await
element
.
getAttribute
(
'rel'
)
expect
(
rel
).
toBe
(
'prefetch'
)
const
as
=
await
element
.
getAttribute
(
'as'
)
expect
(
as
).
toBe
(
'script'
)
expect
(
rel
).
toBe
(
'prefetch'
)
})
expect
(
as
).
toBe
(
'script'
)
)
})
await
browser
.
close
()
)
})
await
browser
.
close
()
})
// This is a workaround to fix https://github.com/zeit/next.js/issues/5860
// TODO: remove this workaround when https://bugs.webkit.org/show_bug.cgi?id=187726 is fixed.
it
(
'It does not add a timestamp to link tags with prefetch attribute'
,
async
()
=>
{
const
browser
=
await
webdriver
(
appPort
,
'/prefetch'
)
const
links
=
await
browser
.
elementsByCss
(
'link[rel=prefetch]'
)
await
Promise
.
all
(
links
.
map
(
async
element
=>
{
const
href
=
await
element
.
getAttribute
(
'href'
)
expect
(
href
).
not
.
toMatch
(
/
\?
ts=/
)
})
)
const
scripts
=
await
browser
.
elementsByCss
(
'script[src]'
)
await
Promise
.
all
(
scripts
.
map
(
async
element
=>
{
const
src
=
await
element
.
getAttribute
(
'src'
)
expect
(
src
).
not
.
toMatch
(
/
\?
ts=/
)
})
)
await
browser
.
close
()
})
it
(
'should reload the page on page script error with prefetch'
,
async
()
=>
{
const
browser
=
await
webdriver
(
appPort
,
'/counter'
)
if
(
global
.
browserName
!==
'chrome'
)
return
const
counter
=
await
browser
.
elementByCss
(
'#increase'
)
.
click
()
.
click
()
.
elementByCss
(
'#counter'
)
.
text
()
expect
(
counter
).
toBe
(
'Counter: 2'
)
// Let the browser to prefetch the page and error it on the console.
// This is a workaround to fix https://github.com/zeit/next.js/issues/5860
await
waitFor
(
3000
)
// TODO: remove this workaround when https://bugs.webkit.org/show_bug.cgi?id=187726 is fixed.
const
browserLogs
=
await
browser
.
log
(
'browser'
)
it
(
'It does not add a timestamp to link tags with prefetch attribute'
,
async
()
=>
{
let
foundLog
=
false
const
browser
=
await
webdriver
(
appPort
,
'/prefetch'
)
browserLogs
.
forEach
(
log
=>
{
const
links
=
await
browser
.
elementsByCss
(
'link[rel=prefetch]'
)
if
(
log
.
message
.
match
(
/
\/
no-such-page
\.
js - Failed to load resource/
))
{
await
Promise
.
all
(
foundLog
=
true
links
.
map
(
async
element
=>
{
}
const
href
=
await
element
.
getAttribute
(
'href'
)
expect
(
href
).
not
.
toMatch
(
/
\?
ts=/
)
})
)
const
scripts
=
await
browser
.
elementsByCss
(
'script[src]'
)
await
Promise
.
all
(
scripts
.
map
(
async
element
=>
{
const
src
=
await
element
.
getAttribute
(
'src'
)
expect
(
src
).
not
.
toMatch
(
/
\?
ts=/
)
})
)
await
browser
.
close
()
})
})
expect
(
foundLog
).
toBe
(
true
)
// When we go to the 404 page, it'll do a hard reload.
it
(
'should reload the page on page script error with prefetch'
,
async
()
=>
{
// So, it's possible for the front proxy to load a page from another zone.
const
browser
=
await
webdriver
(
appPort
,
'/counter'
)
// Since the page is reloaded, when we go back to the counter page again,
if
(
global
.
browserName
!==
'chrome'
)
return
// previous counter value should be gone.
const
counter
=
await
browser
const
counterAfter404Page
=
await
browser
.
elementByCss
(
'#increase'
)
.
elementByCss
(
'#no-such-page-prefetch'
)
.
click
()
.
click
()
.
click
()
.
waitForElementByCss
(
'h1'
)
.
elementByCss
(
'#counter'
)
.
back
()
.
text
()
.
waitForElementByCss
(
'#counter-page'
)
expect
(
counter
).
toBe
(
'Counter: 2'
)
.
elementByCss
(
'#counter'
)
.
text
()
// Let the browser to prefetch the page and error it on the console.
expect
(
counterAfter404Page
).
toBe
(
'Counter: 0'
)
await
waitFor
(
3000
)
const
browserLogs
=
await
browser
.
log
(
'browser'
)
let
foundLog
=
false
browserLogs
.
forEach
(
log
=>
{
if
(
log
.
message
.
match
(
/
\/
no-such-page
\.
js - Failed to load resource/
)
)
{
foundLog
=
true
}
})
expect
(
foundLog
).
toBe
(
true
)
// When we go to the 404 page, it'll do a hard reload.
// So, it's possible for the front proxy to load a page from another zone.
// Since the page is reloaded, when we go back to the counter page again,
// previous counter value should be gone.
const
counterAfter404Page
=
await
browser
.
elementByCss
(
'#no-such-page-prefetch'
)
.
click
()
.
waitForElementByCss
(
'h1'
)
.
back
()
.
waitForElementByCss
(
'#counter-page'
)
.
elementByCss
(
'#counter'
)
.
text
()
expect
(
counterAfter404Page
).
toBe
(
'Counter: 0'
)
await
browser
.
close
()
await
browser
.
close
()
})
})
}
})
})
it
(
'should not expose the compiled page file in development'
,
async
()
=>
{
it
(
'should not expose the compiled page file in development'
,
async
()
=>
{
...
...
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