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
7a2ec416
Unverified
Commit
7a2ec416
authored
Dec 19, 2022
by
Tim Neutkens
Committed by
GitHub
Dec 19, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor more tests to createNextDescribe (#44104)
parent
b8ae447b
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
39 changed files
with
2658 additions
and
3224 deletions
+2658
-3224
ReactRefresh.test.ts
test/development/acceptance-app/ReactRefresh.test.ts
+0
-5
ReactRefreshLogBox-builtins.test.ts
...opment/acceptance-app/ReactRefreshLogBox-builtins.test.ts
+0
-5
ReactRefreshLogBox-scss.test.ts
...evelopment/acceptance-app/ReactRefreshLogBox-scss.test.ts
+0
-5
ReactRefreshLogBox.test.ts
test/development/acceptance-app/ReactRefreshLogBox.test.ts
+0
-5
ReactRefreshLogBoxMisc.test.ts
...development/acceptance-app/ReactRefreshLogBoxMisc.test.ts
+0
-5
ReactRefreshModule.test.ts
test/development/acceptance-app/ReactRefreshModule.test.ts
+0
-5
ReactRefreshRegression.test.ts
...development/acceptance-app/ReactRefreshRegression.test.ts
+0
-5
server-components.test.ts
test/development/acceptance-app/server-components.test.ts
+0
-5
hmr.test.ts
test/development/basic-basepath/hmr.test.ts
+1
-5
hmr.test.ts
test/development/basic/hmr.test.ts
+1
-5
app-alias.test.ts
test/e2e/app-dir/app-alias.test.ts
+38
-49
app-edge-global.test.ts
test/e2e/app-dir/app-edge-global.test.ts
+20
-29
app-edge.test.ts
test/e2e/app-dir/app-edge.test.ts
+62
-70
app-external.test.ts
test/e2e/app-dir/app-external.test.ts
+136
-153
app-middleware.test.ts
test/e2e/app-dir/app-middleware.test.ts
+134
-142
app-static.test.ts
test/e2e/app-dir/app-static.test.ts
+596
-611
asset-prefix.test.ts
test/e2e/app-dir/asset-prefix.test.ts
+36
-56
async-component-preload.test.ts
test/e2e/app-dir/async-component-preload.test.ts
+15
-26
back-button-download-bug.test.ts
test/e2e/app-dir/back-button-download-bug.test.ts
+23
-35
create-root-layout.test.ts
test/e2e/app-dir/create-root-layout.test.ts
+4
-9
dynamic-href.test.ts
test/e2e/app-dir/dynamic-href.test.ts
+54
-66
global-error.test.ts
test/e2e/app-dir/global-error.test.ts
+24
-30
import.test.ts
test/e2e/app-dir/import.test.ts
+16
-30
index.test.ts
test/e2e/app-dir/index.test.ts
+221
-382
layout-params.test.ts
test/e2e/app-dir/layout-params.test.ts
+54
-84
next-font.test.ts
test/e2e/app-dir/next-font.test.ts
+330
-349
next-image.test.ts
test/e2e/app-dir/next-image.test.ts
+258
-299
prefetching.test.ts
test/e2e/app-dir/prefetching.test.ts
+48
-58
rendering.test.ts
test/e2e/app-dir/rendering.test.ts
+104
-121
root-layout.test.ts
test/e2e/app-dir/root-layout.test.ts
+171
-191
rsc-basic.test.ts
test/e2e/app-dir/rsc-basic.test.ts
+85
-98
rsc-errors.test.ts
test/e2e/app-dir/rsc-errors.test.ts
+87
-109
standalone.test.ts
test/e2e/app-dir/standalone.test.ts
+84
-88
trailingslash.test.ts
test/e2e/app-dir/trailingslash.test.ts
+36
-56
vercel-analytics.test.ts
test/e2e/app-dir/vercel-analytics.test.ts
+1
-2
with-babel.test.ts
test/e2e/app-dir/with-babel.test.ts
+13
-28
index.test.ts
test/e2e/transpile-packages/index.test.ts
+1
-2
e2e-utils.ts
test/lib/e2e-utils.ts
+2
-1
base.ts
test/lib/next-modes/base.ts
+3
-0
No files found.
test/development/acceptance-app/ReactRefresh.test.ts
View file @
7a2ec416
...
@@ -5,11 +5,6 @@ import { NextInstance } from 'test/lib/next-modes/base'
...
@@ -5,11 +5,6 @@ import { NextInstance } from 'test/lib/next-modes/base'
import
path
from
'path'
import
path
from
'path'
describe
(
'ReactRefresh app'
,
()
=>
{
describe
(
'ReactRefresh app'
,
()
=>
{
if
(
process
.
env
.
NEXT_TEST_REACT_VERSION
===
'^17'
)
{
it
(
'should skip for react v17'
,
()
=>
{})
return
}
let
next
:
NextInstance
let
next
:
NextInstance
beforeAll
(
async
()
=>
{
beforeAll
(
async
()
=>
{
...
...
test/development/acceptance-app/ReactRefreshLogBox-builtins.test.ts
View file @
7a2ec416
...
@@ -5,11 +5,6 @@ import path from 'path'
...
@@ -5,11 +5,6 @@ import path from 'path'
// TODO-APP: Investigate snapshot mismatch
// TODO-APP: Investigate snapshot mismatch
describe
(
'ReactRefreshLogBox app'
,
()
=>
{
describe
(
'ReactRefreshLogBox app'
,
()
=>
{
if
(
process
.
env
.
NEXT_TEST_REACT_VERSION
===
'^17'
)
{
it
(
'should skip for react v17'
,
()
=>
{})
return
}
let
next
:
NextInstance
let
next
:
NextInstance
beforeAll
(
async
()
=>
{
beforeAll
(
async
()
=>
{
...
...
test/development/acceptance-app/ReactRefreshLogBox-scss.test.ts
View file @
7a2ec416
...
@@ -7,11 +7,6 @@ import path from 'path'
...
@@ -7,11 +7,6 @@ import path from 'path'
// TODO: figure out why snapshots mismatch on GitHub actions
// TODO: figure out why snapshots mismatch on GitHub actions
// specifically but work in docker and locally
// specifically but work in docker and locally
describe
.
skip
(
'ReactRefreshLogBox app'
,
()
=>
{
describe
.
skip
(
'ReactRefreshLogBox app'
,
()
=>
{
if
(
process
.
env
.
NEXT_TEST_REACT_VERSION
===
'^17'
)
{
it
(
'should skip for react v17'
,
()
=>
{})
return
}
let
next
:
NextInstance
let
next
:
NextInstance
beforeAll
(
async
()
=>
{
beforeAll
(
async
()
=>
{
...
...
test/development/acceptance-app/ReactRefreshLogBox.test.ts
View file @
7a2ec416
...
@@ -6,11 +6,6 @@ import { check } from 'next-test-utils'
...
@@ -6,11 +6,6 @@ import { check } from 'next-test-utils'
import
path
from
'path'
import
path
from
'path'
describe
(
'ReactRefreshLogBox app'
,
()
=>
{
describe
(
'ReactRefreshLogBox app'
,
()
=>
{
if
(
process
.
env
.
NEXT_TEST_REACT_VERSION
===
'^17'
)
{
it
(
'should skip for react v17'
,
()
=>
{})
return
}
let
next
:
NextInstance
let
next
:
NextInstance
beforeAll
(
async
()
=>
{
beforeAll
(
async
()
=>
{
...
...
test/development/acceptance-app/ReactRefreshLogBoxMisc.test.ts
View file @
7a2ec416
...
@@ -6,11 +6,6 @@ import path from 'path'
...
@@ -6,11 +6,6 @@ import path from 'path'
// TODO: re-enable these tests after figuring out what is causing
// TODO: re-enable these tests after figuring out what is causing
// them to be so unreliable in CI
// them to be so unreliable in CI
describe
.
skip
(
'ReactRefreshLogBox app'
,
()
=>
{
describe
.
skip
(
'ReactRefreshLogBox app'
,
()
=>
{
if
(
process
.
env
.
NEXT_TEST_REACT_VERSION
===
'^17'
)
{
it
(
'should skip for react v17'
,
()
=>
{})
return
}
let
next
:
NextInstance
let
next
:
NextInstance
beforeAll
(
async
()
=>
{
beforeAll
(
async
()
=>
{
...
...
test/development/acceptance-app/ReactRefreshModule.test.ts
View file @
7a2ec416
...
@@ -4,11 +4,6 @@ import { NextInstance } from 'test/lib/next-modes/base'
...
@@ -4,11 +4,6 @@ import { NextInstance } from 'test/lib/next-modes/base'
import
{
sandbox
}
from
'./helpers'
import
{
sandbox
}
from
'./helpers'
describe
(
'ReactRefreshModule app'
,
()
=>
{
describe
(
'ReactRefreshModule app'
,
()
=>
{
if
(
process
.
env
.
NEXT_TEST_REACT_VERSION
===
'^17'
)
{
it
(
'should skip for react v17'
,
()
=>
{})
return
}
let
next
:
NextInstance
let
next
:
NextInstance
beforeAll
(
async
()
=>
{
beforeAll
(
async
()
=>
{
...
...
test/development/acceptance-app/ReactRefreshRegression.test.ts
View file @
7a2ec416
...
@@ -5,11 +5,6 @@ import { NextInstance } from 'test/lib/next-modes/base'
...
@@ -5,11 +5,6 @@ import { NextInstance } from 'test/lib/next-modes/base'
import
path
from
'path'
import
path
from
'path'
describe
(
'ReactRefreshRegression app'
,
()
=>
{
describe
(
'ReactRefreshRegression app'
,
()
=>
{
if
(
process
.
env
.
NEXT_TEST_REACT_VERSION
===
'^17'
)
{
it
(
'should skip for react v17'
,
()
=>
{})
return
}
let
next
:
NextInstance
let
next
:
NextInstance
beforeAll
(
async
()
=>
{
beforeAll
(
async
()
=>
{
...
...
test/development/acceptance-app/server-components.test.ts
View file @
7a2ec416
...
@@ -6,11 +6,6 @@ import path from 'path'
...
@@ -6,11 +6,6 @@ import path from 'path'
import
{
check
}
from
'next-test-utils'
import
{
check
}
from
'next-test-utils'
describe
(
'Error Overlay for server components'
,
()
=>
{
describe
(
'Error Overlay for server components'
,
()
=>
{
if
(
process
.
env
.
NEXT_TEST_REACT_VERSION
===
'^17'
)
{
it
(
'should skip for react v17'
,
()
=>
{})
return
}
let
next
:
NextInstance
let
next
:
NextInstance
beforeAll
(
async
()
=>
{
beforeAll
(
async
()
=>
{
...
...
test/development/basic-basepath/hmr.test.ts
View file @
7a2ec416
...
@@ -532,14 +532,10 @@ describe('basic HMR', () => {
...
@@ -532,14 +532,10 @@ describe('basic HMR', () => {
)
)
)
)
const
isReact17
=
process
.
env
.
NEXT_TEST_REACT_VERSION
===
'^17'
expect
(
await
hasRedbox
(
browser
)).
toBe
(
true
)
expect
(
await
hasRedbox
(
browser
)).
toBe
(
true
)
// TODO: Replace this when webpack 5 is the default
// TODO: Replace this when webpack 5 is the default
expect
(
await
getRedboxHeader
(
browser
)).
toMatch
(
expect
(
await
getRedboxHeader
(
browser
)).
toMatch
(
`Objects are not valid as a React child (found:
${
`Objects are not valid as a React child (found: [object RegExp]). If you meant to render a collection of children, use an array instead.`
isReact17
?
'/search/'
:
'[object RegExp]'
}
). If you meant to render a collection of children, use an array instead.`
)
)
await
next
.
patchFile
(
aboutPage
,
aboutContent
)
await
next
.
patchFile
(
aboutPage
,
aboutContent
)
...
...
test/development/basic/hmr.test.ts
View file @
7a2ec416
...
@@ -597,14 +597,10 @@ describe('basic HMR', () => {
...
@@ -597,14 +597,10 @@ describe('basic HMR', () => {
)
)
)
)
const
isReact17
=
process
.
env
.
NEXT_TEST_REACT_VERSION
===
'^17'
expect
(
await
hasRedbox
(
browser
)).
toBe
(
true
)
expect
(
await
hasRedbox
(
browser
)).
toBe
(
true
)
// TODO: Replace this when webpack 5 is the default
// TODO: Replace this when webpack 5 is the default
expect
(
await
getRedboxHeader
(
browser
)).
toMatch
(
expect
(
await
getRedboxHeader
(
browser
)).
toMatch
(
`Objects are not valid as a React child (found:
${
`Objects are not valid as a React child (found: [object RegExp]). If you meant to render a collection of children, use an array instead.`
isReact17
?
'/search/'
:
'[object RegExp]'
}
). If you meant to render a collection of children, use an array instead.`
)
)
await
next
.
patchFile
(
aboutPage
,
aboutContent
)
await
next
.
patchFile
(
aboutPage
,
aboutContent
)
...
...
test/e2e/app-dir/app-alias.test.ts
View file @
7a2ec416
import
{
createNext
,
FileRef
}
from
'e2e-utils'
import
{
createNextDescribe
}
from
'e2e-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
{
renderViaHTTP
}
from
'next-test-utils'
import
webdriver
from
'next-webdriver'
import
path
from
'path'
import
path
from
'path'
import
{
readJSON
}
from
'fs-extra'
describe
(
'app-dir alias handling'
,
()
=>
{
createNextDescribe
(
if
((
global
as
any
).
isNextDeploy
)
{
'app-dir alias handling'
,
it
(
'should skip next deploy for now'
,
()
=>
{})
{
return
files
:
path
.
join
(
__dirname
,
'app-alias'
),
}
let
next
:
NextInstance
beforeAll
(
async
()
=>
{
next
=
await
createNext
({
files
:
new
FileRef
(
path
.
join
(
__dirname
,
'app-alias'
)),
dependencies
:
{
dependencies
:
{
react
:
'latest'
,
react
:
'latest'
,
'react-dom'
:
'latest'
,
'react-dom'
:
'latest'
,
...
@@ -26,31 +15,31 @@ describe('app-dir alias handling', () => {
...
@@ -26,31 +15,31 @@ describe('app-dir alias handling', () => {
packageJson
:
{
packageJson
:
{
type
:
'module'
,
type
:
'module'
,
},
},
})
skipDeployment
:
true
,
})
},
afterAll
(()
=>
next
.
destroy
())
({
next
,
isNextDev
})
=>
{
it
(
'should handle typescript paths alias correctly'
,
async
()
=>
{
it
(
'should handle typescript paths alias correctly'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/button'
)
const
html
=
await
next
.
render
(
'/button'
)
expect
(
html
).
toContain
(
'click</button>'
)
expect
(
html
).
toContain
(
'click</button>'
)
})
})
it
(
'should resolve css imports from outside with src folder presented'
,
async
()
=>
{
it
(
'should resolve css imports from outside with src folder presented'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/button'
)
const
browser
=
await
next
.
browser
(
'/button'
)
const
fontSize
=
await
browser
const
fontSize
=
await
browser
.
elementByCss
(
'button'
)
.
elementByCss
(
'button'
)
.
getComputedCss
(
'font-size'
)
.
getComputedCss
(
'font-size'
)
expect
(
fontSize
).
toBe
(
'50px'
)
expect
(
fontSize
).
toBe
(
'50px'
)
})
})
if
(
!
(
global
as
any
).
isNextDev
)
{
if
(
!
isNextDev
)
{
it
(
'should generate app-build-manifest correctly'
,
async
()
=>
{
it
(
'should generate app-build-manifest correctly'
,
async
()
=>
{
// Remove other page CSS files:
// Remove other page CSS files:
const
manifest
=
await
readJSON
(
const
manifest
=
await
next
.
readJSON
(
path
.
join
(
next
.
testDir
,
'.next'
,
'app-build-manifest.json'
)
path
.
join
(
'.next'
,
'app-build-manifest.json'
)
)
)
expect
(
manifest
.
pages
).
not
.
toBeEmptyObject
()
expect
(
manifest
.
pages
).
not
.
toBeEmptyObject
()
})
})
}
}
})
}
)
test/e2e/app-dir/app-edge-global.test.ts
View file @
7a2ec416
import
{
createNext
,
FileRef
}
from
'e2e-utils'
import
{
createNextDescribe
}
from
'e2e-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
{
renderViaHTTP
}
from
'next-test-utils'
import
path
from
'path'
import
path
from
'path'
describe
(
'app-dir global edge configuration'
,
()
=>
{
createNextDescribe
(
if
((
global
as
any
).
isNextDeploy
)
{
'app-dir global edge configuration'
,
it
(
'should skip next deploy for now'
,
()
=>
{})
{
return
files
:
path
.
join
(
__dirname
,
'app-edge-global'
),
}
let
next
:
NextInstance
beforeAll
(
async
()
=>
{
next
=
await
createNext
({
files
:
new
FileRef
(
path
.
join
(
__dirname
,
'app-edge-global'
)),
dependencies
:
{
dependencies
:
{
react
:
'latest'
,
react
:
'latest'
,
'react-dom'
:
'latest'
,
'react-dom'
:
'latest'
,
...
@@ -21,12 +12,12 @@ describe('app-dir global edge configuration', () => {
...
@@ -21,12 +12,12 @@ describe('app-dir global edge configuration', () => {
'@types/react'
:
'latest'
,
'@types/react'
:
'latest'
,
'@types/node'
:
'latest'
,
'@types/node'
:
'latest'
,
},
},
})
skipDeployment
:
true
,
})
},
afterAll
(()
=>
next
.
destroy
())
({
next
})
=>
{
it
(
'should handle edge only routes'
,
async
()
=>
{
it
(
'should handle edge only routes'
,
async
()
=>
{
const
appHtml
=
await
renderViaHTTP
(
next
.
url
,
'/app-edge'
)
const
html
=
await
next
.
render
(
'/app-edge'
)
expect
(
appH
tml
).
toContain
(
'<p>Edge!</p>'
)
expect
(
h
tml
).
toContain
(
'<p>Edge!</p>'
)
})
})
})
}
)
test/e2e/app-dir/app-edge.test.ts
View file @
7a2ec416
import
{
createNext
,
FileRef
}
from
'e2e-utils'
import
{
createNextDescribe
}
from
'e2e-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
{
check
}
from
'next-test-utils'
import
{
check
,
renderViaHTTP
}
from
'next-test-utils'
import
path
from
'path'
import
path
from
'path'
describe
(
'app-dir edge SSR'
,
()
=>
{
createNextDescribe
(
if
((
global
as
any
).
isNextDeploy
)
{
'app-dir edge SSR'
,
it
(
'should skip next deploy for now'
,
()
=>
{})
{
return
files
:
path
.
join
(
__dirname
,
'app-edge'
),
}
let
next
:
NextInstance
beforeAll
(
async
()
=>
{
next
=
await
createNext
({
files
:
new
FileRef
(
path
.
join
(
__dirname
,
'app-edge'
)),
dependencies
:
{
dependencies
:
{
react
:
'latest'
,
react
:
'latest'
,
'react-dom'
:
'latest'
,
'react-dom'
:
'latest'
,
...
@@ -21,15 +13,14 @@ describe('app-dir edge SSR', () => {
...
@@ -21,15 +13,14 @@ describe('app-dir edge SSR', () => {
'@types/react'
:
'latest'
,
'@types/react'
:
'latest'
,
'@types/node'
:
'latest'
,
'@types/node'
:
'latest'
,
},
},
})
skipDeployment
:
true
,
})
},
afterAll
(()
=>
next
.
destroy
())
({
next
})
=>
{
it
(
'should handle edge only routes'
,
async
()
=>
{
it
(
'should handle edge only routes'
,
async
()
=>
{
const
appHtml
=
await
renderViaHTTP
(
next
.
url
,
'/app-edge'
)
const
appHtml
=
await
next
.
render
(
'/app-edge'
)
expect
(
appHtml
).
toContain
(
'<p>Edge!</p>'
)
expect
(
appHtml
).
toContain
(
'<p>Edge!</p>'
)
const
pageHtml
=
await
renderViaHTTP
(
next
.
url
,
'/pages-edge'
)
const
pageHtml
=
await
next
.
render
(
'/pages-edge'
)
expect
(
pageHtml
).
toContain
(
'<p>pages-edge-ssr</p>'
)
expect
(
pageHtml
).
toContain
(
'<p>pages-edge-ssr</p>'
)
})
})
...
@@ -39,10 +30,10 @@ describe('app-dir edge SSR', () => {
...
@@ -39,10 +30,10 @@ describe('app-dir edge SSR', () => {
next
.
on
(
'stderr'
,
(
log
)
=>
{
next
.
on
(
'stderr'
,
(
log
)
=>
{
logs
.
push
(
log
)
logs
.
push
(
log
)
})
})
await
renderViaHTTP
(
next
.
url
,
'app-edge'
)
await
next
.
render
(
'app-edge'
)
expect
(
logs
.
some
((
log
)
=>
log
.
includes
(
`Attempted import error:`
))).
toBe
(
expect
(
false
logs
.
some
((
log
)
=>
log
.
includes
(
`Attempted import error:`
))
)
).
toBe
(
false
)
})
})
it
(
'should handle edge rsc hmr'
,
async
()
=>
{
it
(
'should handle edge rsc hmr'
,
async
()
=>
{
...
@@ -53,14 +44,14 @@ describe('app-dir edge SSR', () => {
...
@@ -53,14 +44,14 @@ describe('app-dir edge SSR', () => {
const
updatedContent
=
content
.
replace
(
'Edge!'
,
'edge-hmr'
)
const
updatedContent
=
content
.
replace
(
'Edge!'
,
'edge-hmr'
)
await
next
.
patchFile
(
pageFile
,
updatedContent
)
await
next
.
patchFile
(
pageFile
,
updatedContent
)
await
check
(
async
()
=>
{
await
check
(
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/app-edge'
)
const
html
=
await
next
.
render
(
'/app-edge'
)
return
html
return
html
},
/edge-hmr/
)
},
/edge-hmr/
)
// Revert
// Revert
await
next
.
patchFile
(
pageFile
,
content
)
await
next
.
patchFile
(
pageFile
,
content
)
await
check
(
async
()
=>
{
await
check
(
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/app-edge'
)
const
html
=
await
next
.
render
(
'/app-edge'
)
return
html
return
html
},
/Edge!/
)
},
/Edge!/
)
})
})
...
@@ -77,4 +68,5 @@ describe('app-dir edge SSR', () => {
...
@@ -77,4 +68,5 @@ describe('app-dir edge SSR', () => {
])
])
})
})
}
}
})
}
)
test/e2e/app-dir/app-external.test.ts
View file @
7a2ec416
import
path
from
'path'
import
path
from
'path'
import
{
renderViaHTTP
,
fetchViaHTTP
}
from
'next-test-utils'
import
{
createNextDescribe
}
from
'e2e-utils'
import
{
createNext
,
FileRef
}
from
'e2e-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
webdriver
from
'next-webdriver'
async
function
resolveStreamResponse
(
response
:
any
,
onData
?:
any
)
{
async
function
resolveStreamResponse
(
response
:
any
,
onData
?:
any
)
{
let
result
=
''
let
result
=
''
...
@@ -18,17 +15,10 @@ async function resolveStreamResponse(response: any, onData?: any) {
...
@@ -18,17 +15,10 @@ async function resolveStreamResponse(response: any, onData?: any) {
return
result
return
result
}
}
describe
(
'app dir - external dependency'
,
()
=>
{
createNextDescribe
(
let
next
:
NextInstance
'app dir - external dependency'
,
{
if
((
global
as
any
).
isNextDeploy
)
{
files
:
path
.
join
(
__dirname
,
'./app-external'
),
it
(
'should skip for deploy mode for now'
,
()
=>
{})
return
}
beforeAll
(
async
()
=>
{
next
=
await
createNext
({
files
:
new
FileRef
(
path
.
join
(
__dirname
,
'./app-external'
)),
dependencies
:
{
dependencies
:
{
'@next/font'
:
'canary'
,
'@next/font'
:
'canary'
,
react
:
'latest'
,
react
:
'latest'
,
...
@@ -46,35 +36,25 @@ describe('app dir - external dependency', () => {
...
@@ -46,35 +36,25 @@ describe('app dir - external dependency', () => {
installCommand
:
'yarn'
,
installCommand
:
'yarn'
,
startCommand
:
(
global
as
any
).
isNextDev
?
'yarn dev'
:
'yarn start'
,
startCommand
:
(
global
as
any
).
isNextDev
?
'yarn dev'
:
'yarn start'
,
buildCommand
:
'yarn build'
,
buildCommand
:
'yarn build'
,
})
skipDeployment
:
true
,
})
},
afterAll
(()
=>
next
.
destroy
())
({
next
})
=>
{
const
{
isNextDeploy
}
=
global
as
any
const
isReact17
=
process
.
env
.
NEXT_TEST_REACT_VERSION
===
'^17'
if
(
isNextDeploy
||
isReact17
)
{
it
(
'should skip tests for next-deploy and react 17'
,
()
=>
{})
return
}
it
(
'should be able to opt-out 3rd party packages being bundled in server components'
,
async
()
=>
{
it
(
'should be able to opt-out 3rd party packages being bundled in server components'
,
async
()
=>
{
await
fetchViaHTTP
(
next
.
url
,
'/react-server/optout'
).
then
(
await
next
.
fetch
(
'/react-server/optout'
).
then
(
async
(
response
)
=>
{
async
(
response
)
=>
{
const
result
=
await
resolveStreamResponse
(
response
)
const
result
=
await
resolveStreamResponse
(
response
)
expect
(
result
).
toContain
(
'Server: index.default'
)
expect
(
result
).
toContain
(
'Server: index.default'
)
expect
(
result
).
toContain
(
'Server subpath: subpath.default'
)
expect
(
result
).
toContain
(
'Server subpath: subpath.default'
)
expect
(
result
).
toContain
(
'Client: index.default'
)
expect
(
result
).
toContain
(
'Client: index.default'
)
expect
(
result
).
toContain
(
'Client subpath: subpath.default'
)
expect
(
result
).
toContain
(
'Client subpath: subpath.default'
)
}
})
)
})
})
it
(
'should handle external async module libraries correctly'
,
async
()
=>
{
it
(
'should handle external async module libraries correctly'
,
async
()
=>
{
const
clientHtml
=
await
renderViaHTTP
(
next
.
url
,
'/external-imports/client'
)
const
clientHtml
=
await
next
.
render
(
'/external-imports/client'
)
const
serverHtml
=
await
renderViaHTTP
(
next
.
url
,
'/external-imports/server'
)
const
serverHtml
=
await
next
.
render
(
'/external-imports/server'
)
const
sharedHtml
=
await
renderViaHTTP
(
next
.
url
,
'/shared-esm-dep'
)
const
sharedHtml
=
await
next
.
render
(
'/shared-esm-dep'
)
const
browser
=
await
webdriver
(
next
.
url
,
'/external-imports/client'
)
const
browser
=
await
next
.
browser
(
'/external-imports/client'
)
const
browserClientText
=
await
browser
.
elementByCss
(
'#content'
).
text
()
const
browserClientText
=
await
browser
.
elementByCss
(
'#content'
).
text
()
function
containClientContent
(
content
)
{
function
containClientContent
(
content
)
{
...
@@ -97,12 +77,12 @@ describe('app dir - external dependency', () => {
...
@@ -97,12 +77,12 @@ describe('app dir - external dependency', () => {
})
})
it
(
'should transpile specific external packages with the `transpilePackages` option'
,
async
()
=>
{
it
(
'should transpile specific external packages with the `transpilePackages` option'
,
async
()
=>
{
const
clientHtml
=
await
renderViaHTTP
(
next
.
url
,
'/external-imports/client'
)
const
clientHtml
=
await
next
.
render
(
'/external-imports/client'
)
expect
(
clientHtml
).
toContain
(
'transpilePackages:5'
)
expect
(
clientHtml
).
toContain
(
'transpilePackages:5'
)
})
})
it
(
'should resolve the subset react in server components based on the react-server condition'
,
async
()
=>
{
it
(
'should resolve the subset react in server components based on the react-server condition'
,
async
()
=>
{
await
fetchViaHTTP
(
next
.
url
,
'/react-server'
).
then
(
async
(
response
)
=>
{
await
next
.
fetch
(
'/react-server'
).
then
(
async
(
response
)
=>
{
const
result
=
await
resolveStreamResponse
(
response
)
const
result
=
await
resolveStreamResponse
(
response
)
expect
(
result
).
toContain
(
'Server: <!-- -->subset'
)
expect
(
result
).
toContain
(
'Server: <!-- -->subset'
)
expect
(
result
).
toContain
(
'Client: <!-- -->full'
)
expect
(
result
).
toContain
(
'Client: <!-- -->full'
)
...
@@ -110,8 +90,9 @@ describe('app dir - external dependency', () => {
...
@@ -110,8 +90,9 @@ describe('app dir - external dependency', () => {
})
})
it
(
'should resolve 3rd party package exports based on the react-server condition'
,
async
()
=>
{
it
(
'should resolve 3rd party package exports based on the react-server condition'
,
async
()
=>
{
await
fetchViaHTTP
(
next
.
url
,
'/react-server/3rd-party-package'
).
then
(
await
next
async
(
response
)
=>
{
.
fetch
(
'/react-server/3rd-party-package'
)
.
then
(
async
(
response
)
=>
{
const
result
=
await
resolveStreamResponse
(
response
)
const
result
=
await
resolveStreamResponse
(
response
)
// Package should be resolved based on the react-server condition,
// Package should be resolved based on the react-server condition,
...
@@ -119,17 +100,18 @@ describe('app dir - external dependency', () => {
...
@@ -119,17 +100,18 @@ describe('app dir - external dependency', () => {
expect
(
result
).
toContain
(
expect
(
result
).
toContain
(
'Server: index.react-server:react.subset:dep.server'
'Server: index.react-server:react.subset:dep.server'
)
)
expect
(
result
).
toContain
(
'Client: index.default:react.full:dep.default'
)
expect
(
result
).
toContain
(
'Client: index.default:react.full:dep.default'
)
// Subpath exports should be resolved based on the condition too.
// Subpath exports should be resolved based on the condition too.
expect
(
result
).
toContain
(
'Server subpath: subpath.react-server'
)
expect
(
result
).
toContain
(
'Server subpath: subpath.react-server'
)
expect
(
result
).
toContain
(
'Client subpath: subpath.default'
)
expect
(
result
).
toContain
(
'Client subpath: subpath.default'
)
}
})
)
})
})
it
(
'should correctly collect global css imports and mark them as side effects'
,
async
()
=>
{
it
(
'should correctly collect global css imports and mark them as side effects'
,
async
()
=>
{
await
fetchViaHTTP
(
next
.
url
,
'/css/a'
).
then
(
async
(
response
)
=>
{
await
next
.
fetch
(
'/css/a'
).
then
(
async
(
response
)
=>
{
const
result
=
await
resolveStreamResponse
(
response
)
const
result
=
await
resolveStreamResponse
(
response
)
// It should include the global CSS import
// It should include the global CSS import
...
@@ -138,7 +120,7 @@ describe('app dir - external dependency', () => {
...
@@ -138,7 +120,7 @@ describe('app dir - external dependency', () => {
})
})
it
(
'should handle external css modules'
,
async
()
=>
{
it
(
'should handle external css modules'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/css/modules'
)
const
browser
=
await
next
.
browser
(
'/css/modules'
)
expect
(
expect
(
await
browser
.
eval
(
await
browser
.
eval
(
...
@@ -148,12 +130,12 @@ describe('app dir - external dependency', () => {
...
@@ -148,12 +130,12 @@ describe('app dir - external dependency', () => {
})
})
it
(
'should use the same export type for packages in both ssr and client'
,
async
()
=>
{
it
(
'should use the same export type for packages in both ssr and client'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/client-dep'
)
const
browser
=
await
next
.
browser
(
'/client-dep'
)
expect
(
await
browser
.
eval
(
`window.document.body.innerText`
)).
toBe
(
'hello'
)
expect
(
await
browser
.
eval
(
`window.document.body.innerText`
)).
toBe
(
'hello'
)
})
})
it
(
'should handle external css modules in pages'
,
async
()
=>
{
it
(
'should handle external css modules in pages'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/test-pages'
)
const
browser
=
await
next
.
browser
(
'/test-pages'
)
expect
(
expect
(
await
browser
.
eval
(
await
browser
.
eval
(
...
@@ -163,7 +145,7 @@ describe('app dir - external dependency', () => {
...
@@ -163,7 +145,7 @@ describe('app dir - external dependency', () => {
})
})
it
(
'should handle external @next/font'
,
async
()
=>
{
it
(
'should handle external @next/font'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/font'
)
const
browser
=
await
next
.
browser
(
'/font'
)
expect
(
expect
(
await
browser
.
eval
(
await
browser
.
eval
(
...
@@ -174,7 +156,7 @@ describe('app dir - external dependency', () => {
...
@@ -174,7 +156,7 @@ describe('app dir - external dependency', () => {
describe
(
'react in external esm packages'
,
()
=>
{
describe
(
'react in external esm packages'
,
()
=>
{
it
(
'should use the same react in client app'
,
async
()
=>
{
it
(
'should use the same react in client app'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/esm/client'
)
const
html
=
await
next
.
render
(
'/esm/client'
)
const
v1
=
html
.
match
(
/App React Version:
([^
<
]
+
)
</
)[
1
]
const
v1
=
html
.
match
(
/App React Version:
([^
<
]
+
)
</
)[
1
]
const
v2
=
html
.
match
(
/External React Version:
([^
<
]
+
)
</
)[
1
]
const
v2
=
html
.
match
(
/External React Version:
([^
<
]
+
)
</
)[
1
]
...
@@ -182,7 +164,7 @@ describe('app dir - external dependency', () => {
...
@@ -182,7 +164,7 @@ describe('app dir - external dependency', () => {
})
})
it
(
'should use the same react in server app'
,
async
()
=>
{
it
(
'should use the same react in server app'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/esm/server'
)
const
html
=
await
next
.
render
(
'/esm/server'
)
const
v1
=
html
.
match
(
/App React Version:
([^
<
]
+
)
</
)[
1
]
const
v1
=
html
.
match
(
/App React Version:
([^
<
]
+
)
</
)[
1
]
const
v2
=
html
.
match
(
/External React Version:
([^
<
]
+
)
</
)[
1
]
const
v2
=
html
.
match
(
/External React Version:
([^
<
]
+
)
</
)[
1
]
...
@@ -190,11 +172,12 @@ describe('app dir - external dependency', () => {
...
@@ -190,11 +172,12 @@ describe('app dir - external dependency', () => {
})
})
it
(
'should use the same react in pages'
,
async
()
=>
{
it
(
'should use the same react in pages'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/test-pages-esm'
)
const
html
=
await
next
.
render
(
'/test-pages-esm'
)
const
v1
=
html
.
match
(
/App React Version:
([^
<
]
+
)
</
)[
1
]
const
v1
=
html
.
match
(
/App React Version:
([^
<
]
+
)
</
)[
1
]
const
v2
=
html
.
match
(
/External React Version:
([^
<
]
+
)
</
)[
1
]
const
v2
=
html
.
match
(
/External React Version:
([^
<
]
+
)
</
)[
1
]
expect
(
v1
).
toBe
(
v2
)
expect
(
v1
).
toBe
(
v2
)
})
})
})
})
})
}
)
test/e2e/app-dir/app-middleware.test.ts
View file @
7a2ec416
/* eslint-env jest */
/* eslint-env jest */
import
{
createNextDescribe
,
FileRef
}
from
'e2e-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
{
fetchViaHTTP
,
renderViaHTTP
}
from
'next-test-utils'
import
{
createNext
,
FileRef
}
from
'e2e-utils'
import
cheerio
from
'cheerio'
import
cheerio
from
'cheerio'
import
path
from
'path'
import
path
from
'path'
describe
(
'app-dir with middleware'
,
()
=>
{
createNextDescribe
(
if
((
global
as
any
).
isNextDeploy
)
{
'app-dir with middleware'
,
it
(
'should skip next deploy for now'
,
()
=>
{})
{
return
files
:
path
.
join
(
__dirname
,
'app-middleware'
),
}
skipDeployment
:
true
,
},
let
next
:
NextInstance
({
next
})
=>
{
afterAll
(()
=>
next
.
destroy
())
beforeAll
(
async
()
=>
{
next
=
await
createNext
({
files
:
new
FileRef
(
path
.
join
(
__dirname
,
'app-middleware'
)),
})
})
describe
.
each
([
describe
.
each
([
{
{
title
:
'Serverless Functions'
,
title
:
'Serverless Functions'
,
...
@@ -42,7 +31,7 @@ describe('app-dir with middleware', () => {
...
@@ -42,7 +31,7 @@ describe('app-dir with middleware', () => {
},
},
])(
'Mutate request headers for $title'
,
({
path
,
toJson
})
=>
{
])(
'Mutate request headers for $title'
,
({
path
,
toJson
})
=>
{
it
(
`Adds new headers`
,
async
()
=>
{
it
(
`Adds new headers`
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
next
.
url
,
path
,
null
,
{
const
res
=
await
next
.
fetch
(
path
,
null
,
{
headers
:
{
headers
:
{
'x-from-client'
:
'hello-from-client'
,
'x-from-client'
:
'hello-from-client'
,
},
},
...
@@ -54,8 +43,7 @@ describe('app-dir with middleware', () => {
...
@@ -54,8 +43,7 @@ describe('app-dir with middleware', () => {
})
})
it
(
`Deletes headers`
,
async
()
=>
{
it
(
`Deletes headers`
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
const
res
=
await
next
.
fetch
(
next
.
url
,
path
,
path
,
{
{
'remove-headers'
:
'x-from-client1,x-from-client2'
,
'remove-headers'
:
'x-from-client1,x-from-client2'
,
...
@@ -80,13 +68,16 @@ describe('app-dir with middleware', () => {
...
@@ -80,13 +68,16 @@ describe('app-dir with middleware', () => {
expect
(
expect
(
res
.
headers
.
get
(
'x-middleware-request-x-from-middleware'
)
res
.
headers
.
get
(
'x-middleware-request-x-from-middleware'
)
).
toBeNull
()
).
toBeNull
()
expect
(
res
.
headers
.
get
(
'x-middleware-request-x-from-client1'
)).
toBeNull
()
expect
(
expect
(
res
.
headers
.
get
(
'x-middleware-request-x-from-client2'
)).
toBeNull
()
res
.
headers
.
get
(
'x-middleware-request-x-from-client1'
)
).
toBeNull
()
expect
(
res
.
headers
.
get
(
'x-middleware-request-x-from-client2'
)
).
toBeNull
()
})
})
it
(
`Updates headers`
,
async
()
=>
{
it
(
`Updates headers`
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
const
res
=
await
next
.
fetch
(
next
.
url
,
path
,
path
,
{
{
'update-headers'
:
'update-headers'
:
...
@@ -112,24 +103,23 @@ describe('app-dir with middleware', () => {
...
@@ -112,24 +103,23 @@ describe('app-dir with middleware', () => {
expect
(
expect
(
res
.
headers
.
get
(
'x-middleware-request-x-from-middleware'
)
res
.
headers
.
get
(
'x-middleware-request-x-from-middleware'
)
).
toBeNull
()
).
toBeNull
()
expect
(
res
.
headers
.
get
(
'x-middleware-request-x-from-client1'
)).
toBeNull
()
expect
(
expect
(
res
.
headers
.
get
(
'x-middleware-request-x-from-client2'
)).
toBeNull
()
res
.
headers
.
get
(
'x-middleware-request-x-from-client1'
)
expect
(
res
.
headers
.
get
(
'x-middleware-request-x-from-client3'
)).
toBeNull
()
).
toBeNull
()
expect
(
res
.
headers
.
get
(
'x-middleware-request-x-from-client2'
)
).
toBeNull
()
expect
(
res
.
headers
.
get
(
'x-middleware-request-x-from-client3'
)
).
toBeNull
()
})
})
})
})
})
describe
(
'app dir middleware without pages dir'
,
()
=>
{
if
((
global
as
any
).
isNextDeploy
)
{
it
(
'should skip next deploy for now'
,
()
=>
{})
return
}
}
)
let
next
:
NextInstance
createNextDescribe
(
'app dir middleware without pages dir'
,
afterAll
(()
=>
next
.
destroy
())
{
beforeAll
(
async
()
=>
{
next
=
await
createNext
({
files
:
{
files
:
{
app
:
new
FileRef
(
path
.
join
(
__dirname
,
'app-middleware/app'
)),
app
:
new
FileRef
(
path
.
join
(
__dirname
,
'app-middleware/app'
)),
'next.config.js'
:
new
FileRef
(
'next.config.js'
:
new
FileRef
(
...
@@ -147,12 +137,14 @@ describe('app dir middleware without pages dir', () => {
...
@@ -147,12 +137,14 @@ describe('app dir middleware without pages dir', () => {
}
}
`
,
`
,
},
},
})
skipDeployment
:
true
,
})
},
({
next
})
=>
{
it
(
`Updates headers`
,
async
()
=>
{
// eslint-disable-next-line jest/no-identical-title
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/headers'
)
it
(
'Updates headers'
,
async
()
=>
{
const
html
=
await
next
.
render
(
'/headers'
)
expect
(
html
).
toContain
(
'redirected'
)
expect
(
html
).
toContain
(
'redirected'
)
})
})
})
}
)
test/e2e/app-dir/app-static.test.ts
View file @
7a2ec416
This diff is collapsed.
Click to expand it.
test/e2e/app-dir/asset-prefix.test.ts
View file @
7a2ec416
import
{
createNext
,
FileRef
}
from
'e2e-utils'
import
{
createNextDescribe
}
from
'e2e-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
{
fetchViaHTTP
,
renderViaHTTP
}
from
'next-test-utils'
import
path
from
'path'
import
path
from
'path'
import
cheerio
from
'cheerio'
import
webdriver
from
'next-webdriver'
describe
(
'app-dir assetPrefix handling'
,
()
=>
{
createNextDescribe
(
if
((
global
as
any
).
isNextDeploy
)
{
'app-dir assetPrefix handling'
,
it
(
'should skip next deploy for now'
,
()
=>
{})
{
return
files
:
path
.
join
(
__dirname
,
'asset-prefix'
),
}
skipDeployment
:
true
,
let
next
:
NextInstance
beforeAll
(
async
()
=>
{
next
=
await
createNext
({
files
:
new
FileRef
(
path
.
join
(
__dirname
,
'asset-prefix'
)),
dependencies
:
{
react
:
'latest'
,
'react-dom'
:
'latest'
,
},
},
skipStart
:
true
,
({
next
})
=>
{
})
await
next
.
start
()
})
afterAll
(()
=>
next
.
destroy
())
it
(
'should redirect route when requesting it directly'
,
async
()
=>
{
it
(
'should redirect route when requesting it directly'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
const
res
=
await
next
.
fetch
(
next
.
url
,
'/a/'
,
'/a/'
,
{},
{},
{
{
...
@@ -41,22 +21,22 @@ describe('app-dir assetPrefix handling', () => {
...
@@ -41,22 +21,22 @@ describe('app-dir assetPrefix handling', () => {
})
})
it
(
'should render link'
,
async
()
=>
{
it
(
'should render link'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/'
)
const
$
=
await
next
.
render$
(
'/'
)
const
$
=
cheerio
.
load
(
html
)
expect
(
$
(
'#to-a-trailing-slash'
).
attr
(
'href'
)).
toBe
(
'/a'
)
expect
(
$
(
'#to-a-trailing-slash'
).
attr
(
'href'
)).
toBe
(
'/a'
)
})
})
it
(
'should redirect route when requesting it directly by browser'
,
async
()
=>
{
it
(
'should redirect route when requesting it directly by browser'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/a'
)
const
browser
=
await
next
.
browser
(
'/a'
)
expect
(
await
browser
.
waitForElementByCss
(
'#a-page'
).
text
()).
toBe
(
'A page'
)
expect
(
await
browser
.
waitForElementByCss
(
'#a-page'
).
text
()).
toBe
(
'A page'
)
})
})
it
(
'should redirect route when clicking link'
,
async
()
=>
{
it
(
'should redirect route when clicking link'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/'
)
const
browser
=
await
next
.
browser
(
'/'
)
await
browser
await
browser
.
elementByCss
(
'#to-a-trailing-slash'
)
.
elementByCss
(
'#to-a-trailing-slash'
)
.
click
()
.
click
()
.
waitForElementByCss
(
'#a-page'
)
.
waitForElementByCss
(
'#a-page'
)
expect
(
await
browser
.
waitForElementByCss
(
'#a-page'
).
text
()).
toBe
(
'A page'
)
expect
(
await
browser
.
waitForElementByCss
(
'#a-page'
).
text
()).
toBe
(
'A page'
)
})
})
})
}
)
test/e2e/app-dir/async-component-preload.test.ts
View file @
7a2ec416
import
{
createNext
,
FileRef
}
from
'e2e-utils'
import
{
createNextDescribe
}
from
'e2e-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
webdriver
from
'next-webdriver'
import
path
from
'path'
import
path
from
'path'
describe
(
'async-component-preload'
,
()
=>
{
createNextDescribe
(
if
((
global
as
any
).
isNextDeploy
)
{
'async-component-preload'
,
it
(
'should skip next deploy for now'
,
()
=>
{})
{
return
files
:
path
.
join
(
__dirname
,
'async-component-preload'
),
}
skipDeployment
:
true
,
let
next
:
NextInstance
beforeAll
(
async
()
=>
{
next
=
await
createNext
({
files
:
new
FileRef
(
path
.
join
(
__dirname
,
'async-component-preload'
)),
dependencies
:
{
react
:
'latest'
,
'react-dom'
:
'latest'
,
},
},
})
({
next
})
=>
{
})
afterAll
(()
=>
next
.
destroy
())
it
(
'should handle redirect in an async page'
,
async
()
=>
{
it
(
'should handle redirect in an async page'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/'
)
const
browser
=
await
next
.
browser
(
'/'
)
expect
(
await
browser
.
waitForElementByCss
(
'#success'
).
text
()).
toBe
(
'Success'
)
expect
(
await
browser
.
waitForElementByCss
(
'#success'
).
text
()).
toBe
(
'Success'
)
})
})
})
}
)
test/e2e/app-dir/back-button-download-bug.test.ts
View file @
7a2ec416
import
{
createNext
,
FileRef
}
from
'e2e-utils'
import
{
createNextDescribe
}
from
'e2e-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
path
from
'path'
import
path
from
'path'
import
webdriver
from
'next-webdriver'
// TODO-APP: fix test as it's failing randomly
// TODO-APP: fix test as it's failing randomly
describe
.
skip
(
'app-dir back button download bug'
,
()
=>
{
describe
.
skip
(
'app-dir back button download bug'
,
()
=>
{
if
((
global
as
any
).
isNextDeploy
)
{
createNextDescribe
(
it
(
'should skip next deploy for now'
,
()
=>
{})
'app-dir back button download bug'
,
return
{
}
files
:
path
.
join
(
__dirname
,
'back-button-download-bug'
),
skipDeployment
:
true
,
let
next
:
NextInstance
beforeAll
(
async
()
=>
{
next
=
await
createNext
({
files
:
new
FileRef
(
path
.
join
(
__dirname
,
'back-button-download-bug'
)),
dependencies
:
{
react
:
'latest'
,
'react-dom'
:
'latest'
,
},
},
skipStart
:
true
,
({
next
})
=>
{
})
await
next
.
start
()
})
afterAll
(()
=>
next
.
destroy
())
it
(
'should redirect route when clicking link'
,
async
()
=>
{
it
(
'should redirect route when clicking link'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/'
)
const
browser
=
await
next
.
browser
(
'/'
)
const
text
=
await
browser
const
text
=
await
browser
.
elementByCss
(
'#to-post-1'
)
.
elementByCss
(
'#to-post-1'
)
.
click
()
.
click
()
...
@@ -37,6 +21,10 @@ describe.skip('app-dir back button download bug', () => {
...
@@ -37,6 +21,10 @@ describe.skip('app-dir back button download bug', () => {
await
browser
.
back
()
await
browser
.
back
()
expect
(
await
browser
.
waitForElementByCss
(
'#home-page'
).
text
()).
toBe
(
'Home!'
)
expect
(
await
browser
.
waitForElementByCss
(
'#home-page'
).
text
()).
toBe
(
'Home!'
)
})
})
}
)
})
})
test/e2e/app-dir/create-root-layout.test.ts
View file @
7a2ec416
import
path
from
'path'
import
path
from
'path'
import
{
createNext
,
FileRef
}
from
'e2e-utils'
import
{
createNext
,
FileRef
}
from
'e2e-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
webdriver
from
'next-webdriver'
import
{
check
}
from
'next-test-utils'
import
{
check
}
from
'next-test-utils'
describe
(
'app-dir create root layout'
,
()
=>
{
describe
(
'app-dir create root layout'
,
()
=>
{
...
@@ -12,10 +11,6 @@ describe('app-dir create root layout', () => {
...
@@ -12,10 +11,6 @@ describe('app-dir create root layout', () => {
return
return
}
}
if
(
process
.
env
.
NEXT_TEST_REACT_VERSION
===
'^17'
)
{
it
(
'should skip for react v17'
,
()
=>
{})
return
}
let
next
:
NextInstance
let
next
:
NextInstance
if
(
isDev
)
{
if
(
isDev
)
{
...
@@ -39,7 +34,7 @@ describe('app-dir create root layout', () => {
...
@@ -39,7 +34,7 @@ describe('app-dir create root layout', () => {
it
(
'create root layout'
,
async
()
=>
{
it
(
'create root layout'
,
async
()
=>
{
const
outputIndex
=
next
.
cliOutput
.
length
const
outputIndex
=
next
.
cliOutput
.
length
const
browser
=
await
webdriver
(
next
.
url
,
'/route'
)
const
browser
=
await
next
.
browser
(
'/route'
)
expect
(
await
browser
.
elementById
(
'page-text'
).
text
()).
toBe
(
expect
(
await
browser
.
elementById
(
'page-text'
).
text
()).
toBe
(
'Hello world!'
'Hello world!'
...
@@ -101,7 +96,7 @@ describe('app-dir create root layout', () => {
...
@@ -101,7 +96,7 @@ describe('app-dir create root layout', () => {
it
(
'create root layout'
,
async
()
=>
{
it
(
'create root layout'
,
async
()
=>
{
const
outputIndex
=
next
.
cliOutput
.
length
const
outputIndex
=
next
.
cliOutput
.
length
const
browser
=
await
webdriver
(
next
.
url
,
'/'
)
const
browser
=
await
next
.
browser
(
'/'
)
expect
(
await
browser
.
elementById
(
'page-text'
).
text
()).
toBe
(
expect
(
await
browser
.
elementById
(
'page-text'
).
text
()).
toBe
(
'Hello world'
'Hello world'
...
@@ -168,7 +163,7 @@ describe('app-dir create root layout', () => {
...
@@ -168,7 +163,7 @@ describe('app-dir create root layout', () => {
it
(
'create root layout'
,
async
()
=>
{
it
(
'create root layout'
,
async
()
=>
{
const
outputIndex
=
next
.
cliOutput
.
length
const
outputIndex
=
next
.
cliOutput
.
length
const
browser
=
await
webdriver
(
next
.
url
,
'/route/second/inner'
)
const
browser
=
await
next
.
browser
(
'/route/second/inner'
)
expect
(
await
browser
.
elementById
(
'page-text'
).
text
()).
toBe
(
expect
(
await
browser
.
elementById
(
'page-text'
).
text
()).
toBe
(
'Hello world'
'Hello world'
...
@@ -236,7 +231,7 @@ describe('app-dir create root layout', () => {
...
@@ -236,7 +231,7 @@ describe('app-dir create root layout', () => {
it
(
'create root layout'
,
async
()
=>
{
it
(
'create root layout'
,
async
()
=>
{
const
outputIndex
=
next
.
cliOutput
.
length
const
outputIndex
=
next
.
cliOutput
.
length
const
browser
=
await
webdriver
(
next
.
url
,
'/'
)
const
browser
=
await
next
.
browser
(
'/'
)
expect
(
await
browser
.
elementById
(
'page-text'
).
text
()).
toBe
(
expect
(
await
browser
.
elementById
(
'page-text'
).
text
()).
toBe
(
'Hello world!'
'Hello world!'
...
...
test/e2e/app-dir/dynamic-href.test.ts
View file @
7a2ec416
import
{
createNext
,
FileRef
}
from
'e2e-utils'
import
{
createNextDescribe
}
from
'e2e-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
{
getRedboxDescription
,
hasRedbox
}
from
'next-test-utils'
import
{
getRedboxDescription
,
hasRedbox
}
from
'next-test-utils'
import
path
from
'path'
import
path
from
'path'
import
webdriver
from
'next-webdriver'
describe
(
'dynamic-href'
,
()
=>
{
createNextDescribe
(
const
isDev
=
(
global
as
any
).
isNextDev
'dynamic-href'
,
if
((
global
as
any
).
isNextDeploy
)
{
{
it
(
'should skip next deploy for now'
,
()
=>
{})
files
:
path
.
join
(
__dirname
,
'dynamic-href'
),
return
skipDeployment
:
true
,
}
let
next
:
NextInstance
beforeAll
(
async
()
=>
{
next
=
await
createNext
({
files
:
new
FileRef
(
path
.
join
(
__dirname
,
'dynamic-href'
)),
dependencies
:
{
react
:
'latest'
,
'react-dom'
:
'latest'
,
},
},
})
({
isNextDev
:
isDev
,
next
})
=>
{
})
afterAll
(()
=>
next
.
destroy
())
if
(
isDev
)
{
if
(
isDev
)
{
it
(
'should error when using dynamic href.pathname in app dir'
,
async
()
=>
{
it
(
'should error when using dynamic href.pathname in app dir'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/object'
)
const
browser
=
await
next
.
browser
(
'/object'
)
// Error should show up
// Error should show up
expect
(
await
hasRedbox
(
browser
,
true
)).
toBeTrue
()
expect
(
await
hasRedbox
(
browser
,
true
)).
toBeTrue
()
...
@@ -43,7 +28,9 @@ describe('dynamic-href', () => {
...
@@ -43,7 +28,9 @@ describe('dynamic-href', () => {
"pathname: '/object/slug'"
"pathname: '/object/slug'"
)
)
)
)
expect
(
await
browser
.
waitForElementByCss
(
'#link'
).
text
()).
toBe
(
'to slug'
)
expect
(
await
browser
.
waitForElementByCss
(
'#link'
).
text
()).
toBe
(
'to slug'
)
// Navigate to new page
// Navigate to new page
await
browser
.
elementByCss
(
'#link'
).
click
()
await
browser
.
elementByCss
(
'#link'
).
click
()
...
@@ -54,7 +41,7 @@ describe('dynamic-href', () => {
...
@@ -54,7 +41,7 @@ describe('dynamic-href', () => {
})
})
it
(
'should error when using dynamic href in app dir'
,
async
()
=>
{
it
(
'should error when using dynamic href in app dir'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/string'
)
const
browser
=
await
next
.
browser
(
'/string'
)
// Error should show up
// Error should show up
expect
(
await
hasRedbox
(
browser
,
true
)).
toBeTrue
()
expect
(
await
hasRedbox
(
browser
,
true
)).
toBeTrue
()
...
@@ -64,12 +51,13 @@ describe('dynamic-href', () => {
...
@@ -64,12 +51,13 @@ describe('dynamic-href', () => {
})
})
}
else
{
}
else
{
it
(
'should not error on /object in prod'
,
async
()
=>
{
it
(
'should not error on /object in prod'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/object'
)
const
browser
=
await
next
.
browser
(
'/object'
)
expect
(
await
browser
.
elementByCss
(
'#link'
).
text
()).
toBe
(
'to slug'
)
expect
(
await
browser
.
elementByCss
(
'#link'
).
text
()).
toBe
(
'to slug'
)
})
})
it
(
'should not error on /string in prod'
,
async
()
=>
{
it
(
'should not error on /string in prod'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/string'
)
const
browser
=
await
next
.
browser
(
'/string'
)
expect
(
await
browser
.
elementByCss
(
'#link'
).
text
()).
toBe
(
'to slug'
)
expect
(
await
browser
.
elementByCss
(
'#link'
).
text
()).
toBe
(
'to slug'
)
})
})
}
}
})
}
)
test/e2e/app-dir/global-error.test.ts
View file @
7a2ec416
import
path
from
'path'
import
path
from
'path'
import
{
getRedboxHeader
,
hasRedbox
}
from
'next-test-utils'
import
{
getRedboxHeader
,
hasRedbox
}
from
'next-test-utils'
import
{
createNext
,
FileRef
}
from
'e2e-utils'
import
{
createNextDescribe
}
from
'e2e-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
webdriver
from
'next-webdriver'
describe
(
'app dir - global error'
,
()
=>
{
let
next
:
NextInstance
const
isDev
=
(
global
as
any
).
isNextDev
beforeAll
(
async
()
=>
{
next
=
await
createNext
({
files
:
new
FileRef
(
path
.
join
(
__dirname
,
'./global-error'
)),
})
})
afterAll
(()
=>
next
.
destroy
())
createNextDescribe
(
'app dir - global error'
,
{
files
:
path
.
join
(
__dirname
,
'./global-error'
),
},
({
next
,
isNextDev
})
=>
{
it
(
'should trigger error component when an error happens during rendering'
,
async
()
=>
{
it
(
'should trigger error component when an error happens during rendering'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/throw'
)
const
browser
=
await
next
.
browser
(
'/throw'
)
await
browser
await
browser
.
waitForElementByCss
(
'#error-trigger-button'
)
.
waitForElementByCss
(
'#error-trigger-button'
)
.
elementByCss
(
'#error-trigger-button'
)
.
elementByCss
(
'#error-trigger-button'
)
.
click
()
.
click
()
if
(
is
Dev
)
{
if
(
isNext
Dev
)
{
expect
(
await
hasRedbox
(
browser
)).
toBe
(
true
)
expect
(
await
hasRedbox
(
browser
)).
toBe
(
true
)
expect
(
await
getRedboxHeader
(
browser
)).
toMatch
(
/Error: Client error/
)
expect
(
await
getRedboxHeader
(
browser
)).
toMatch
(
/Error: Client error/
)
}
else
{
}
else
{
...
@@ -32,4 +25,5 @@ describe('app dir - global error', () => {
...
@@ -32,4 +25,5 @@ describe('app dir - global error', () => {
)
)
}
}
})
})
})
}
)
test/e2e/app-dir/import.test.ts
View file @
7a2ec416
import
path
from
'path'
import
path
from
'path'
import
cheerio
from
'cheerio'
import
{
createNextDescribe
}
from
'e2e-utils'
import
{
createNext
,
FileRef
}
from
'e2e-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
{
renderViaHTTP
}
from
'next-test-utils'
describe
(
'app dir imports'
,
()
=>
{
createNextDescribe
(
if
(
process
.
env
.
NEXT_TEST_REACT_VERSION
===
'^17'
)
{
'app dir imports'
,
it
(
'should skip for react v17'
,
()
=>
{})
{
return
files
:
path
.
join
(
__dirname
,
'import'
),
}
let
next
:
NextInstance
function
runTests
()
{
beforeAll
(
async
()
=>
{
next
=
await
createNext
({
files
:
new
FileRef
(
path
.
join
(
__dirname
,
'import'
)),
dependencies
:
{
dependencies
:
{
react
:
'latest'
,
react
:
'latest'
,
'react-dom'
:
'latest'
,
'react-dom'
:
'latest'
,
...
@@ -22,17 +12,13 @@ describe('app dir imports', () => {
...
@@ -22,17 +12,13 @@ describe('app dir imports', () => {
'@types/react'
:
'latest'
,
'@types/react'
:
'latest'
,
'@types/node'
:
'latest'
,
'@types/node'
:
'latest'
,
},
},
})
},
})
({
next
})
=>
{
afterAll
(()
=>
next
.
destroy
())
;[
'js'
,
'jsx'
,
'ts'
,
'tsx'
].
forEach
((
ext
)
=>
{
;[
'js'
,
'jsx'
,
'ts'
,
'tsx'
].
forEach
((
ext
)
=>
{
it
(
`we can import all components from .
${
ext
}
`
,
async
()
=>
{
it
(
`we can import all components from .
${
ext
}
`
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
`/
${
ext
}
`
)
const
$
=
await
next
.
render$
(
`/
${
ext
}
`
)
const
$
=
cheerio
.
load
(
html
)
expect
(
$
(
'#js'
).
text
()).
toBe
(
'CompJs'
)
expect
(
$
(
'#js'
).
text
()).
toBe
(
'CompJs'
)
})
})
})
})
}
}
)
runTests
()
})
test/e2e/app-dir/index.test.ts
View file @
7a2ec416
This diff is collapsed.
Click to expand it.
test/e2e/app-dir/layout-params.test.ts
View file @
7a2ec416
import
path
from
'path'
import
path
from
'path'
import
{
renderViaHTTP
}
from
'next-test-utils'
import
{
createNextDescribe
}
from
'e2e-utils'
import
{
createNext
,
FileRef
}
from
'e2e-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
cheerio
from
'cheerio'
describe
(
'app dir - layout params'
,
()
=>
{
createNextDescribe
(
let
next
:
NextInstance
'app dir - layout params'
,
{
beforeAll
(
async
()
=>
{
files
:
path
.
join
(
__dirname
,
'./layout-params'
),
next
=
await
createNext
({
files
:
new
FileRef
(
path
.
join
(
__dirname
,
'./layout-params'
)),
dependencies
:
{
dependencies
:
{
react
:
'latest'
,
react
:
'latest'
,
'react-dom'
:
'latest'
,
'react-dom'
:
'latest'
,
...
@@ -17,23 +12,11 @@ describe('app dir - layout params', () => {
...
@@ -17,23 +12,11 @@ describe('app dir - layout params', () => {
'@types/react'
:
'latest'
,
'@types/react'
:
'latest'
,
'@types/node'
:
'latest'
,
'@types/node'
:
'latest'
,
},
},
})
},
})
({
next
})
=>
{
afterAll
(()
=>
next
.
destroy
())
const
isReact17
=
process
.
env
.
NEXT_TEST_REACT_VERSION
===
'^17'
if
(
isReact17
)
{
it
(
'should skip tests for react 17'
,
()
=>
{})
return
}
describe
(
'basic params'
,
()
=>
{
describe
(
'basic params'
,
()
=>
{
it
(
'check layout without params get no params'
,
async
()
=>
{
it
(
'check layout without params get no params'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/base/something/another'
)
const
$
=
await
next
.
render$
(
'/base/something/another'
)
const
$
=
cheerio
.
load
(
html
)
const
ids
=
[
'#root-layout'
,
'#lvl1-layout'
]
const
ids
=
[
'#root-layout'
,
'#lvl1-layout'
]
ids
.
forEach
((
divId
)
=>
{
ids
.
forEach
((
divId
)
=>
{
const
params
=
$
(
`
${
divId
}
> div`
)
const
params
=
$
(
`
${
divId
}
> div`
)
...
@@ -42,18 +25,14 @@ describe('app dir - layout params', () => {
...
@@ -42,18 +25,14 @@ describe('app dir - layout params', () => {
})
})
it
(
"check layout renders just it's params"
,
async
()
=>
{
it
(
"check layout renders just it's params"
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/base/something/another'
)
const
$
=
await
next
.
render$
(
'/base/something/another'
)
const
$
=
cheerio
.
load
(
html
)
expect
(
$
(
'#lvl2-layout > div'
).
length
).
toBe
(
1
)
expect
(
$
(
'#lvl2-layout > div'
).
length
).
toBe
(
1
)
expect
(
$
(
'#lvl2-param1'
).
text
()).
toBe
(
'"something"'
)
expect
(
$
(
'#lvl2-param1'
).
text
()).
toBe
(
'"something"'
)
})
})
it
(
'check topmost layout renders all params'
,
async
()
=>
{
it
(
'check topmost layout renders all params'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/base/something/another'
)
const
$
=
await
next
.
render$
(
'/base/something/another'
)
const
$
=
cheerio
.
load
(
html
)
expect
(
$
(
'#lvl3-layout > div'
).
length
).
toBe
(
2
)
expect
(
$
(
'#lvl3-layout > div'
).
length
).
toBe
(
2
)
expect
(
$
(
'#lvl3-param1'
).
text
()).
toBe
(
'"something"'
)
expect
(
$
(
'#lvl3-param1'
).
text
()).
toBe
(
'"something"'
)
...
@@ -63,23 +42,15 @@ describe('app dir - layout params', () => {
...
@@ -63,23 +42,15 @@ describe('app dir - layout params', () => {
describe
(
'catchall params'
,
()
=>
{
describe
(
'catchall params'
,
()
=>
{
it
(
'should give catchall params just to last layout'
,
async
()
=>
{
it
(
'should give catchall params just to last layout'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/catchall/something/another'
)
const
$
=
await
next
.
render$
(
'/catchall/something/another'
)
const
$
=
cheerio
.
load
(
html
)
expect
(
$
(
`#root-layout > div`
).
length
).
toBe
(
0
)
expect
(
$
(
`#root-layout > div`
).
length
).
toBe
(
0
)
expect
(
$
(
'#lvl2-layout > div'
).
length
).
toBe
(
1
)
expect
(
$
(
'#lvl2-layout > div'
).
length
).
toBe
(
1
)
expect
(
$
(
'#lvl2-params'
).
text
()).
toBe
(
'["something","another"]'
)
expect
(
$
(
'#lvl2-params'
).
text
()).
toBe
(
'["something","another"]'
)
})
})
it
(
'should give optional catchall params just to last layout'
,
async
()
=>
{
it
(
'should give optional catchall params just to last layout'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
const
$
=
await
next
.
render$
(
'/optional-catchall/something/another'
)
next
.
url
,
'/optional-catchall/something/another'
)
const
$
=
cheerio
.
load
(
html
)
expect
(
$
(
`#root-layout > div`
).
length
).
toBe
(
0
)
expect
(
$
(
`#root-layout > div`
).
length
).
toBe
(
0
)
...
@@ -88,12 +59,11 @@ describe('app dir - layout params', () => {
...
@@ -88,12 +59,11 @@ describe('app dir - layout params', () => {
})
})
it
(
"should give empty optional catchall params won't give params to any layout"
,
async
()
=>
{
it
(
"should give empty optional catchall params won't give params to any layout"
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/optional-catchall'
)
const
$
=
await
next
.
render$
(
'/optional-catchall'
)
const
$
=
cheerio
.
load
(
html
)
expect
(
$
(
`#root-layout > div`
).
length
).
toBe
(
0
)
expect
(
$
(
`#root-layout > div`
).
length
).
toBe
(
0
)
expect
(
$
(
'#lvl2-layout > div'
).
length
).
toBe
(
0
)
expect
(
$
(
'#lvl2-layout > div'
).
length
).
toBe
(
0
)
})
})
})
})
})
}
)
test/e2e/app-dir/next-font.test.ts
View file @
7a2ec416
import
{
createNext
,
FileRef
}
from
'e2e-utils'
import
{
createNextDescribe
}
from
'e2e-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
{
getRedboxSource
,
hasRedbox
}
from
'next-test-utils'
import
{
getRedboxSource
,
hasRedbox
,
renderViaHTTP
}
from
'next-test-utils'
import
cheerio
from
'cheerio'
import
path
from
'path'
import
path
from
'path'
import
webdriver
from
'next-webdriver'
describe
(
'app dir next-font'
,
()
=>
{
createNextDescribe
(
const
isDev
=
(
global
as
any
).
isNextDev
'app dir next-font'
,
if
((
global
as
any
).
isNextDeploy
)
{
{
it
(
'should skip next deploy for now'
,
()
=>
{})
files
:
path
.
join
(
__dirname
,
'next-font'
),
return
}
let
next
:
NextInstance
beforeAll
(
async
()
=>
{
next
=
await
createNext
({
files
:
new
FileRef
(
path
.
join
(
__dirname
,
'next-font'
)),
dependencies
:
{
dependencies
:
{
'@next/font'
:
'canary'
,
'@next/font'
:
'canary'
,
react
:
'latest'
,
react
:
'latest'
,
'react-dom'
:
'latest'
,
'react-dom'
:
'latest'
,
},
},
skipStart
:
true
,
skipDeployment
:
true
,
})
},
await
next
.
start
()
({
next
,
isNextDev
:
isDev
})
=>
{
})
afterAll
(()
=>
next
.
destroy
())
describe
(
'import values'
,
()
=>
{
describe
(
'import values'
,
()
=>
{
it
(
'should have correct values at /'
,
async
()
=>
{
it
(
'should have correct values at /'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/'
)
const
$
=
await
next
.
render$
(
'/'
)
const
$
=
cheerio
.
load
(
html
)
// layout
// layout
expect
(
JSON
.
parse
(
$
(
'#root-layout'
).
text
())).
toEqual
({
expect
(
JSON
.
parse
(
$
(
'#root-layout'
).
text
())).
toEqual
({
...
@@ -61,8 +46,7 @@ describe('app dir next-font', () => {
...
@@ -61,8 +46,7 @@ describe('app dir next-font', () => {
})
})
it
(
'should have correct values at /client'
,
async
()
=>
{
it
(
'should have correct values at /client'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/client'
)
const
$
=
await
next
.
render$
(
'/client'
)
const
$
=
cheerio
.
load
(
html
)
// root layout
// root layout
expect
(
JSON
.
parse
(
$
(
'#root-layout'
).
text
())).
toEqual
({
expect
(
JSON
.
parse
(
$
(
'#root-layout'
).
text
())).
toEqual
({
...
@@ -101,7 +85,7 @@ describe('app dir next-font', () => {
...
@@ -101,7 +85,7 @@ describe('app dir next-font', () => {
describe
(
'computed styles'
,
()
=>
{
describe
(
'computed styles'
,
()
=>
{
it
(
'should have correct styles at /'
,
async
()
=>
{
it
(
'should have correct styles at /'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/'
)
const
browser
=
await
next
.
browser
(
'/'
)
// layout
// layout
expect
(
expect
(
...
@@ -156,7 +140,7 @@ describe('app dir next-font', () => {
...
@@ -156,7 +140,7 @@ describe('app dir next-font', () => {
})
})
it
(
'should have correct styles at /client'
,
async
()
=>
{
it
(
'should have correct styles at /client'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/client'
)
const
browser
=
await
next
.
browser
(
'/client'
)
// root layout
// root layout
expect
(
expect
(
...
@@ -231,8 +215,7 @@ describe('app dir next-font', () => {
...
@@ -231,8 +215,7 @@ describe('app dir next-font', () => {
if
(
!
isDev
)
{
if
(
!
isDev
)
{
describe
(
'preload'
,
()
=>
{
describe
(
'preload'
,
()
=>
{
it
(
'should preload correctly with server components'
,
async
()
=>
{
it
(
'should preload correctly with server components'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/'
)
const
$
=
await
next
.
render$
(
'/'
)
const
$
=
cheerio
.
load
(
html
)
// Preconnect
// Preconnect
expect
(
$
(
'link[rel="preconnect"]'
).
length
).
toBe
(
0
)
expect
(
$
(
'link[rel="preconnect"]'
).
length
).
toBe
(
0
)
...
@@ -262,8 +245,7 @@ describe('app dir next-font', () => {
...
@@ -262,8 +245,7 @@ describe('app dir next-font', () => {
})
})
it
(
'should preload correctly with client components'
,
async
()
=>
{
it
(
'should preload correctly with client components'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/client'
)
const
$
=
await
next
.
render$
(
'/client'
)
const
$
=
cheerio
.
load
(
html
)
// Preconnect
// Preconnect
expect
(
$
(
'link[rel="preconnect"]'
).
length
).
toBe
(
0
)
expect
(
$
(
'link[rel="preconnect"]'
).
length
).
toBe
(
0
)
...
@@ -295,8 +277,7 @@ describe('app dir next-font', () => {
...
@@ -295,8 +277,7 @@ describe('app dir next-font', () => {
})
})
it
(
'should preload correctly with layout using fonts'
,
async
()
=>
{
it
(
'should preload correctly with layout using fonts'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/layout-with-fonts'
)
const
$
=
await
next
.
render$
(
'/layout-with-fonts'
)
const
$
=
cheerio
.
load
(
html
)
// Preconnect
// Preconnect
expect
(
$
(
'link[rel="preconnect"]'
).
length
).
toBe
(
0
)
expect
(
$
(
'link[rel="preconnect"]'
).
length
).
toBe
(
0
)
...
@@ -321,8 +302,7 @@ describe('app dir next-font', () => {
...
@@ -321,8 +302,7 @@ describe('app dir next-font', () => {
})
})
it
(
'should preload correctly with page using fonts'
,
async
()
=>
{
it
(
'should preload correctly with page using fonts'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/page-with-fonts'
)
const
$
=
await
next
.
render$
(
'/page-with-fonts'
)
const
$
=
cheerio
.
load
(
html
)
// Preconnect
// Preconnect
expect
(
$
(
'link[rel="preconnect"]'
).
length
).
toBe
(
0
)
expect
(
$
(
'link[rel="preconnect"]'
).
length
).
toBe
(
0
)
...
@@ -351,7 +331,7 @@ describe('app dir next-font', () => {
...
@@ -351,7 +331,7 @@ describe('app dir next-font', () => {
if
(
isDev
)
{
if
(
isDev
)
{
describe
(
'Dev errors'
,
()
=>
{
describe
(
'Dev errors'
,
()
=>
{
it
(
'should recover on font loader error'
,
async
()
=>
{
it
(
'should recover on font loader error'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/'
)
const
browser
=
await
next
.
browser
(
'/'
)
const
font1Content
=
await
next
.
readFile
(
'fonts/index.js'
)
const
font1Content
=
await
next
.
readFile
(
'fonts/index.js'
)
// Break file
// Break file
...
@@ -370,4 +350,5 @@ describe('app dir next-font', () => {
...
@@ -370,4 +350,5 @@ describe('app dir next-font', () => {
})
})
})
})
}
}
})
}
)
test/e2e/app-dir/next-image.test.ts
View file @
7a2ec416
import
{
createNext
,
FileRef
}
from
'e2e-utils'
import
{
createNextDescribe
}
from
'e2e-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
{
fetchViaHTTP
,
renderViaHTTP
}
from
'next-test-utils'
import
cheerio
from
'cheerio'
import
path
from
'path'
import
path
from
'path'
import
webdriver
from
'next-webdriver'
describe
(
'app dir next-image'
,
()
=>
{
createNextDescribe
(
if
((
global
as
any
).
isNextDeploy
)
{
'app dir next-image'
,
it
(
'should skip next deploy for now'
,
()
=>
{})
{
return
files
:
path
.
join
(
__dirname
,
'next-image'
),
}
skipDeployment
:
true
,
let
next
:
NextInstance
beforeAll
(
async
()
=>
{
next
=
await
createNext
({
files
:
new
FileRef
(
path
.
join
(
__dirname
,
'next-image'
)),
dependencies
:
{
react
:
'latest'
,
'react-dom'
:
'latest'
,
},
},
skipStart
:
true
,
({
next
})
=>
{
})
await
next
.
start
()
})
afterAll
(()
=>
next
.
destroy
())
describe
(
'ssr content'
,
()
=>
{
describe
(
'ssr content'
,
()
=>
{
it
(
'should render images on / route'
,
async
()
=>
{
it
(
'should render images on / route'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/'
)
const
$
=
await
next
.
render$
(
'/'
)
const
$
=
cheerio
.
load
(
html
)
const
layout
=
$
(
'#app-layout'
)
const
layout
=
$
(
'#app-layout'
)
expect
(
layout
.
attr
(
'src'
)).
toBe
(
expect
(
layout
.
attr
(
'src'
)).
toBe
(
...
@@ -57,8 +38,7 @@ describe('app dir next-image', () => {
...
@@ -57,8 +38,7 @@ describe('app dir next-image', () => {
})
})
it
(
'should render images on /client route'
,
async
()
=>
{
it
(
'should render images on /client route'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/client'
)
const
$
=
await
next
.
render$
(
'/client'
)
const
$
=
cheerio
.
load
(
html
)
const
root
=
$
(
'#app-layout'
)
const
root
=
$
(
'#app-layout'
)
expect
(
root
.
attr
(
'src'
)).
toBe
(
expect
(
root
.
attr
(
'src'
)).
toBe
(
...
@@ -94,8 +74,7 @@ describe('app dir next-image', () => {
...
@@ -94,8 +74,7 @@ describe('app dir next-image', () => {
})
})
it
(
'should render images nested under page dir on /nested route'
,
async
()
=>
{
it
(
'should render images nested under page dir on /nested route'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/nested'
)
const
$
=
await
next
.
render$
(
'/nested'
)
const
$
=
cheerio
.
load
(
html
)
const
root
=
$
(
'#app-layout'
)
const
root
=
$
(
'#app-layout'
)
expect
(
root
.
attr
(
'src'
)).
toBe
(
expect
(
root
.
attr
(
'src'
)).
toBe
(
...
@@ -133,7 +112,7 @@ describe('app dir next-image', () => {
...
@@ -133,7 +112,7 @@ describe('app dir next-image', () => {
describe
(
'browser content'
,
()
=>
{
describe
(
'browser content'
,
()
=>
{
it
(
'should render images on / route'
,
async
()
=>
{
it
(
'should render images on / route'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/'
)
const
browser
=
await
next
.
browser
(
'/'
)
const
layout
=
await
browser
.
elementById
(
'app-layout'
)
const
layout
=
await
browser
.
elementById
(
'app-layout'
)
expect
(
await
layout
.
getAttribute
(
'src'
)).
toBe
(
expect
(
await
layout
.
getAttribute
(
'src'
)).
toBe
(
...
@@ -161,7 +140,7 @@ describe('app dir next-image', () => {
...
@@ -161,7 +140,7 @@ describe('app dir next-image', () => {
})
})
it
(
'should render images on /client route'
,
async
()
=>
{
it
(
'should render images on /client route'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/client'
)
const
browser
=
await
next
.
browser
(
'/client'
)
const
root
=
await
browser
.
elementById
(
'app-layout'
)
const
root
=
await
browser
.
elementById
(
'app-layout'
)
expect
(
await
root
.
getAttribute
(
'src'
)).
toBe
(
expect
(
await
root
.
getAttribute
(
'src'
)).
toBe
(
...
@@ -197,7 +176,7 @@ describe('app dir next-image', () => {
...
@@ -197,7 +176,7 @@ describe('app dir next-image', () => {
})
})
it
(
'should render images nested under page dir on /nested route'
,
async
()
=>
{
it
(
'should render images nested under page dir on /nested route'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/nested'
)
const
browser
=
await
next
.
browser
(
'/nested'
)
const
root
=
await
browser
.
elementById
(
'app-layout'
)
const
root
=
await
browser
.
elementById
(
'app-layout'
)
expect
(
await
root
.
getAttribute
(
'src'
)).
toBe
(
expect
(
await
root
.
getAttribute
(
'src'
)).
toBe
(
...
@@ -235,80 +214,60 @@ describe('app dir next-image', () => {
...
@@ -235,80 +214,60 @@ describe('app dir next-image', () => {
describe
(
'image content'
,
()
=>
{
describe
(
'image content'
,
()
=>
{
it
(
'should render images on / route'
,
async
()
=>
{
it
(
'should render images on / route'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/'
)
const
$
=
await
next
.
render$
(
'/'
)
const
$
=
cheerio
.
load
(
html
)
const
res1
=
await
fetchViaHTTP
(
next
.
url
,
$
(
'#app-layout'
).
attr
(
'src'
))
const
res1
=
await
next
.
fetch
(
$
(
'#app-layout'
).
attr
(
'src'
))
expect
(
res1
.
status
).
toBe
(
200
)
expect
(
res1
.
status
).
toBe
(
200
)
expect
(
res1
.
headers
.
get
(
'content-type'
)).
toBe
(
'image/png'
)
expect
(
res1
.
headers
.
get
(
'content-type'
)).
toBe
(
'image/png'
)
const
res2
=
await
fetchViaHTTP
(
next
.
url
,
$
(
'#app-page'
).
attr
(
'src'
))
const
res2
=
await
next
.
fetch
(
$
(
'#app-page'
).
attr
(
'src'
))
expect
(
res2
.
status
).
toBe
(
200
)
expect
(
res2
.
status
).
toBe
(
200
)
expect
(
res2
.
headers
.
get
(
'content-type'
)).
toBe
(
'image/png'
)
expect
(
res2
.
headers
.
get
(
'content-type'
)).
toBe
(
'image/png'
)
const
res3
=
await
fetchViaHTTP
(
next
.
url
,
$
(
'#app-comp'
).
attr
(
'src'
))
const
res3
=
await
next
.
fetch
(
$
(
'#app-comp'
).
attr
(
'src'
))
expect
(
res3
.
status
).
toBe
(
200
)
expect
(
res3
.
status
).
toBe
(
200
)
expect
(
res3
.
headers
.
get
(
'content-type'
)).
toBe
(
'image/png'
)
expect
(
res3
.
headers
.
get
(
'content-type'
)).
toBe
(
'image/png'
)
})
})
it
(
'should render images on /client route'
,
async
()
=>
{
it
(
'should render images on /client route'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/client'
)
const
$
=
await
next
.
render$
(
'/client'
)
const
$
=
cheerio
.
load
(
html
)
const
res1
=
await
fetchViaHTTP
(
next
.
url
,
$
(
'#app-layout'
).
attr
(
'src'
))
const
res1
=
await
next
.
fetch
(
$
(
'#app-layout'
).
attr
(
'src'
))
expect
(
res1
.
status
).
toBe
(
200
)
expect
(
res1
.
status
).
toBe
(
200
)
expect
(
res1
.
headers
.
get
(
'content-type'
)).
toBe
(
'image/png'
)
expect
(
res1
.
headers
.
get
(
'content-type'
)).
toBe
(
'image/png'
)
const
res2
=
await
fetchViaHTTP
(
const
res2
=
await
next
.
fetch
(
$
(
'#app-client-layout'
).
attr
(
'src'
))
next
.
url
,
$
(
'#app-client-layout'
).
attr
(
'src'
)
)
expect
(
res2
.
status
).
toBe
(
200
)
expect
(
res2
.
status
).
toBe
(
200
)
expect
(
res2
.
headers
.
get
(
'content-type'
)).
toBe
(
'image/png'
)
expect
(
res2
.
headers
.
get
(
'content-type'
)).
toBe
(
'image/png'
)
const
res3
=
await
fetchViaHTTP
(
const
res3
=
await
next
.
fetch
(
$
(
'#app-client-page'
).
attr
(
'src'
))
next
.
url
,
$
(
'#app-client-page'
).
attr
(
'src'
)
)
expect
(
res3
.
status
).
toBe
(
200
)
expect
(
res3
.
status
).
toBe
(
200
)
expect
(
res3
.
headers
.
get
(
'content-type'
)).
toBe
(
'image/png'
)
expect
(
res3
.
headers
.
get
(
'content-type'
)).
toBe
(
'image/png'
)
const
res4
=
await
fetchViaHTTP
(
const
res4
=
await
next
.
fetch
(
$
(
'#app-client-comp'
).
attr
(
'src'
))
next
.
url
,
$
(
'#app-client-comp'
).
attr
(
'src'
)
)
expect
(
res4
.
status
).
toBe
(
200
)
expect
(
res4
.
status
).
toBe
(
200
)
expect
(
res4
.
headers
.
get
(
'content-type'
)).
toBe
(
'image/png'
)
expect
(
res4
.
headers
.
get
(
'content-type'
)).
toBe
(
'image/png'
)
})
})
it
(
'should render images nested under page dir on /nested route'
,
async
()
=>
{
it
(
'should render images nested under page dir on /nested route'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/nested'
)
const
$
=
await
next
.
render$
(
'/nested'
)
const
$
=
cheerio
.
load
(
html
)
const
res1
=
await
fetchViaHTTP
(
next
.
url
,
$
(
'#app-layout'
).
attr
(
'src'
))
const
res1
=
await
next
.
fetch
(
$
(
'#app-layout'
).
attr
(
'src'
))
expect
(
res1
.
status
).
toBe
(
200
)
expect
(
res1
.
status
).
toBe
(
200
)
expect
(
res1
.
headers
.
get
(
'content-type'
)).
toBe
(
'image/png'
)
expect
(
res1
.
headers
.
get
(
'content-type'
)).
toBe
(
'image/png'
)
const
res2
=
await
fetchViaHTTP
(
const
res2
=
await
next
.
fetch
(
$
(
'#app-nested-layout'
).
attr
(
'src'
))
next
.
url
,
$
(
'#app-nested-layout'
).
attr
(
'src'
)
)
expect
(
res2
.
status
).
toBe
(
200
)
expect
(
res2
.
status
).
toBe
(
200
)
expect
(
res2
.
headers
.
get
(
'content-type'
)).
toBe
(
'image/jpeg'
)
expect
(
res2
.
headers
.
get
(
'content-type'
)).
toBe
(
'image/jpeg'
)
const
res3
=
await
fetchViaHTTP
(
const
res3
=
await
next
.
fetch
(
$
(
'#app-nested-page'
).
attr
(
'src'
))
next
.
url
,
$
(
'#app-nested-page'
).
attr
(
'src'
)
)
expect
(
res3
.
status
).
toBe
(
200
)
expect
(
res3
.
status
).
toBe
(
200
)
expect
(
res3
.
headers
.
get
(
'content-type'
)).
toBe
(
'image/jpeg'
)
expect
(
res3
.
headers
.
get
(
'content-type'
)).
toBe
(
'image/jpeg'
)
const
res4
=
await
fetchViaHTTP
(
const
res4
=
await
next
.
fetch
(
$
(
'#app-nested-comp'
).
attr
(
'src'
))
next
.
url
,
$
(
'#app-nested-comp'
).
attr
(
'src'
)
)
expect
(
res4
.
status
).
toBe
(
200
)
expect
(
res4
.
status
).
toBe
(
200
)
expect
(
res4
.
headers
.
get
(
'content-type'
)).
toBe
(
'image/jpeg'
)
expect
(
res4
.
headers
.
get
(
'content-type'
)).
toBe
(
'image/jpeg'
)
})
})
})
})
})
}
)
test/e2e/app-dir/prefetching.test.ts
View file @
7a2ec416
import
{
createNext
,
FileRef
}
from
'e2e-utils'
import
{
createNextDescribe
}
from
'e2e-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
{
waitFor
}
from
'next-test-utils'
import
{
waitFor
}
from
'next-test-utils'
import
path
from
'path'
import
path
from
'path'
import
webdriver
from
'next-webdriver'
describe
(
'app dir prefetching'
,
()
=>
{
createNextDescribe
(
'app dir prefetching'
,
{
files
:
path
.
join
(
__dirname
,
'app-prefetch'
),
skipDeployment
:
true
,
},
({
next
,
isNextDev
})
=>
{
// TODO: re-enable for dev after https://vercel.slack.com/archives/C035J346QQL/p1663822388387959 is resolved (Sep 22nd 2022)
// TODO: re-enable for dev after https://vercel.slack.com/archives/C035J346QQL/p1663822388387959 is resolved (Sep 22nd 2022)
if
((
global
as
any
).
isNextDeploy
||
(
global
as
any
).
isNextDev
)
{
if
(
isNextDev
)
{
it
(
'should skip next deploy for now'
,
()
=>
{})
it
(
'should skip next deploy for now'
,
()
=>
{})
return
return
}
}
let
next
:
NextInstance
beforeAll
(
async
()
=>
{
next
=
await
createNext
({
files
:
new
FileRef
(
path
.
join
(
__dirname
,
'app-prefetch'
)),
dependencies
:
{
react
:
'latest'
,
'react-dom'
:
'latest'
,
},
skipStart
:
true
,
})
await
next
.
start
()
})
afterAll
(()
=>
next
.
destroy
())
it
(
'should show layout eagerly when prefetched with loading one level down'
,
async
()
=>
{
it
(
'should show layout eagerly when prefetched with loading one level down'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/'
)
const
browser
=
await
next
.
browser
(
'/'
)
// Ensure the page is prefetched
// Ensure the page is prefetched
await
waitFor
(
1000
)
await
waitFor
(
1000
)
...
@@ -53,11 +42,12 @@ describe('app dir prefetching', () => {
...
@@ -53,11 +42,12 @@ describe('app dir prefetching', () => {
})
})
it
(
'should not have prefetch error for static path'
,
async
()
=>
{
it
(
'should not have prefetch error for static path'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/'
)
const
browser
=
await
next
.
browser
(
'/'
)
await
browser
.
eval
(
'window.nd.router.prefetch("/dashboard/123")'
)
await
browser
.
eval
(
'window.nd.router.prefetch("/dashboard/123")'
)
await
waitFor
(
3000
)
await
waitFor
(
3000
)
await
browser
.
eval
(
'window.nd.router.push("/dashboard/123")'
)
await
browser
.
eval
(
'window.nd.router.push("/dashboard/123")'
)
expect
(
next
.
cliOutput
).
not
.
toContain
(
'ReferenceError'
)
expect
(
next
.
cliOutput
).
not
.
toContain
(
'ReferenceError'
)
expect
(
next
.
cliOutput
).
not
.
toContain
(
'is not defined'
)
expect
(
next
.
cliOutput
).
not
.
toContain
(
'is not defined'
)
})
})
})
}
)
test/e2e/app-dir/rendering.test.ts
View file @
7a2ec416
import
{
createNext
,
FileRef
}
from
'e2e-utils'
import
{
createNextDescribe
}
from
'e2e-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
{
waitFor
}
from
'next-test-utils'
import
{
renderViaHTTP
,
fetchViaHTTP
,
waitFor
}
from
'next-test-utils'
import
path
from
'path'
import
path
from
'path'
import
cheerio
from
'cheerio'
import
cheerio
from
'cheerio'
describe
(
'app dir rendering'
,
()
=>
{
createNextDescribe
(
if
((
global
as
any
).
isNextDeploy
)
{
'app dir rendering'
,
it
(
'should skip next deploy for now'
,
()
=>
{})
{
return
files
:
path
.
join
(
__dirname
,
'app-rendering'
),
}
skipDeployment
:
true
,
const
isDev
=
(
global
as
any
).
isNextDev
let
next
:
NextInstance
beforeAll
(
async
()
=>
{
next
=
await
createNext
({
files
:
new
FileRef
(
path
.
join
(
__dirname
,
'app-rendering'
)),
dependencies
:
{
react
:
'latest'
,
'react-dom'
:
'latest'
,
},
},
})
({
next
,
isNextDev
:
isDev
})
=>
{
})
afterAll
(()
=>
next
.
destroy
())
it
(
'should serve app/page.server.js at /'
,
async
()
=>
{
it
(
'should serve app/page.server.js at /'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/'
)
const
html
=
await
next
.
render
(
'/'
)
expect
(
html
).
toContain
(
'app/page.server.js'
)
expect
(
html
).
toContain
(
'app/page.server.js'
)
})
})
describe
(
'SSR only'
,
()
=>
{
describe
(
'SSR only'
,
()
=>
{
it
(
'should run data in layout and page'
,
async
()
=>
{
it
(
'should run data in layout and page'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/ssr-only/nested'
)
const
$
=
await
next
.
render$
(
'/ssr-only/nested'
)
const
$
=
cheerio
.
load
(
html
)
expect
(
$
(
'#layout-message'
).
text
()).
toBe
(
'hello from layout'
)
expect
(
$
(
'#layout-message'
).
text
()).
toBe
(
'hello from layout'
)
expect
(
$
(
'#page-message'
).
text
()).
toBe
(
'hello from page'
)
expect
(
$
(
'#page-message'
).
text
()).
toBe
(
'hello from page'
)
})
})
it
(
'should run data fetch in parallel'
,
async
()
=>
{
it
(
'should run data fetch in parallel'
,
async
()
=>
{
const
startTime
=
Date
.
now
()
const
startTime
=
Date
.
now
()
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/ssr-only/slow'
)
const
$
=
await
next
.
render$
(
'/ssr-only/slow'
)
const
endTime
=
Date
.
now
()
const
endTime
=
Date
.
now
()
const
duration
=
endTime
-
startTime
const
duration
=
endTime
-
startTime
// Each part takes 5 seconds so it should be below 10 seconds
// Each part takes 5 seconds so it should be below 10 seconds
// Using 7 seconds to ensure external factors causing slight slowness don't fail the tests
// Using 7 seconds to ensure external factors causing slight slowness don't fail the tests
expect
(
duration
<
7000
).
toBe
(
true
)
expect
(
duration
<
7000
).
toBe
(
true
)
const
$
=
cheerio
.
load
(
html
)
expect
(
$
(
'#slow-layout-message'
).
text
()).
toBe
(
'hello from slow layout'
)
expect
(
$
(
'#slow-layout-message'
).
text
()).
toBe
(
'hello from slow layout'
)
expect
(
$
(
'#slow-page-message'
).
text
()).
toBe
(
'hello from slow page'
)
expect
(
$
(
'#slow-page-message'
).
text
()).
toBe
(
'hello from slow page'
)
})
})
...
@@ -53,8 +37,7 @@ describe('app dir rendering', () => {
...
@@ -53,8 +37,7 @@ describe('app dir rendering', () => {
describe
(
'static only'
,
()
=>
{
describe
(
'static only'
,
()
=>
{
it
(
'should run data in layout and page'
,
async
()
=>
{
it
(
'should run data in layout and page'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/static-only/nested'
)
const
$
=
await
next
.
render$
(
'/static-only/nested'
)
const
$
=
cheerio
.
load
(
html
)
expect
(
$
(
'#layout-message'
).
text
()).
toBe
(
'hello from layout'
)
expect
(
$
(
'#layout-message'
).
text
()).
toBe
(
'hello from layout'
)
expect
(
$
(
'#page-message'
).
text
()).
toBe
(
'hello from page'
)
expect
(
$
(
'#page-message'
).
text
()).
toBe
(
'hello from page'
)
})
})
...
@@ -63,7 +46,7 @@ describe('app dir rendering', () => {
...
@@ -63,7 +46,7 @@ describe('app dir rendering', () => {
isDev
?
'during development'
:
'and use cached version for production'
isDev
?
'during development'
:
'and use cached version for production'
}
`
,
async
()
=>
{
}
`
,
async
()
=>
{
// const startTime = Date.now()
// const startTime = Date.now()
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/static-only/slow'
)
const
$
=
await
next
.
render$
(
'/static-only/slow'
)
// const endTime = Date.now()
// const endTime = Date.now()
// const duration = endTime - startTime
// const duration = endTime - startTime
// Each part takes 5 seconds so it should be below 10 seconds
// Each part takes 5 seconds so it should be below 10 seconds
...
@@ -71,7 +54,6 @@ describe('app dir rendering', () => {
...
@@ -71,7 +54,6 @@ describe('app dir rendering', () => {
// TODO: cache static props in prod
// TODO: cache static props in prod
// expect(duration < (isDev ? 7000 : 2000)).toBe(true)
// expect(duration < (isDev ? 7000 : 2000)).toBe(true)
// expect(duration < 7000).toBe(true)
// expect(duration < 7000).toBe(true)
const
$
=
cheerio
.
load
(
html
)
expect
(
$
(
'#slow-layout-message'
).
text
()).
toBe
(
'hello from slow layout'
)
expect
(
$
(
'#slow-layout-message'
).
text
()).
toBe
(
'hello from slow layout'
)
expect
(
$
(
'#slow-page-message'
).
text
()).
toBe
(
'hello from slow page'
)
expect
(
$
(
'#slow-page-message'
).
text
()).
toBe
(
'hello from slow page'
)
})
})
...
@@ -80,7 +62,7 @@ describe('app dir rendering', () => {
...
@@ -80,7 +62,7 @@ describe('app dir rendering', () => {
describe
(
'ISR'
,
()
=>
{
describe
(
'ISR'
,
()
=>
{
it
(
'should revalidate the page when revalidate is configured'
,
async
()
=>
{
it
(
'should revalidate the page when revalidate is configured'
,
async
()
=>
{
const
getPage
=
async
()
=>
{
const
getPage
=
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
next
.
url
,
'isr-multiple/nested'
)
const
res
=
await
next
.
fetch
(
'isr-multiple/nested'
)
const
html
=
await
res
.
text
()
const
html
=
await
res
.
text
()
return
{
return
{
...
@@ -120,10 +102,10 @@ describe('app dir rendering', () => {
...
@@ -120,10 +102,10 @@ describe('app dir rendering', () => {
describe
.
skip
(
'mixed static and dynamic'
,
()
=>
{
describe
.
skip
(
'mixed static and dynamic'
,
()
=>
{
it
(
'should generate static data during build and use it'
,
async
()
=>
{
it
(
'should generate static data during build and use it'
,
async
()
=>
{
const
getPage
=
async
()
=>
{
const
getPage
=
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'isr-ssr-combined/nested'
)
const
$
=
await
next
.
render$
(
'isr-ssr-combined/nested'
)
return
{
return
{
$
:
cheerio
.
load
(
html
)
,
$
,
}
}
}
}
const
{
$
}
=
await
getPage
()
const
{
$
}
=
await
getPage
()
...
@@ -144,4 +126,5 @@ describe('app dir rendering', () => {
...
@@ -144,4 +126,5 @@ describe('app dir rendering', () => {
expect
(
pageNow
).
toBe
(
pageNowSecond
)
expect
(
pageNow
).
toBe
(
pageNowSecond
)
})
})
})
})
})
}
)
test/e2e/app-dir/root-layout.test.ts
View file @
7a2ec416
import
path
from
'path'
import
path
from
'path'
import
{
createNext
,
FileRef
}
from
'e2e-utils'
import
{
createNextDescribe
}
from
'e2e-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
webdriver
from
'next-webdriver'
import
{
getRedboxSource
,
hasRedbox
}
from
'next-test-utils'
import
{
getRedboxSource
,
hasRedbox
}
from
'next-test-utils'
describe
(
'app-dir root layout'
,
()
=>
{
createNextDescribe
(
const
isDev
=
(
global
as
any
).
isNextDev
'app-dir root layout'
,
{
if
((
global
as
any
).
isNextDeploy
)
{
files
:
path
.
join
(
__dirname
,
'root-layout'
),
it
(
'should skip next deploy for now'
,
()
=>
{})
skipDeployment
:
true
,
return
}
let
next
:
NextInstance
beforeAll
(
async
()
=>
{
next
=
await
createNext
({
files
:
{
app
:
new
FileRef
(
path
.
join
(
__dirname
,
'root-layout/app'
)),
'next.config.js'
:
new
FileRef
(
path
.
join
(
__dirname
,
'root-layout/next.config.js'
)
),
},
dependencies
:
{
react
:
'latest'
,
'react-dom'
:
'latest'
,
},
},
})
({
next
,
isNextDev
:
isDev
})
=>
{
})
afterAll
(()
=>
next
.
destroy
())
if
(
isDev
)
{
if
(
isDev
)
{
// TODO-APP: re-enable after reworking the error overlay.
// TODO-APP: re-enable after reworking the error overlay.
describe
.
skip
(
'Missing required tags'
,
()
=>
{
describe
.
skip
(
'Missing required tags'
,
()
=>
{
it
(
'should error on page load'
,
async
()
=>
{
it
(
'should error on page load'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/missing-tags'
,
{
const
browser
=
await
next
.
browser
(
'/missing-tags'
,
{
waitHydration
:
false
,
waitHydration
:
false
,
})
})
...
@@ -47,7 +26,7 @@ describe('app-dir root layout', () => {
...
@@ -47,7 +26,7 @@ describe('app-dir root layout', () => {
})
})
it
(
'should error on page navigation'
,
async
()
=>
{
it
(
'should error on page navigation'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/has-tags'
,
{
const
browser
=
await
next
.
browser
(
'/has-tags'
,
{
waitHydration
:
false
,
waitHydration
:
false
,
})
})
await
browser
.
elementByCss
(
'a'
).
click
()
await
browser
.
elementByCss
(
'a'
).
click
()
...
@@ -61,7 +40,7 @@ describe('app-dir root layout', () => {
...
@@ -61,7 +40,7 @@ describe('app-dir root layout', () => {
})
})
it
(
'should error on page load on static generation'
,
async
()
=>
{
it
(
'should error on page load on static generation'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/static-missing-tags/slug'
,
{
const
browser
=
await
next
.
browser
(
'/static-missing-tags/slug'
,
{
waitHydration
:
false
,
waitHydration
:
false
,
})
})
...
@@ -77,7 +56,7 @@ describe('app-dir root layout', () => {
...
@@ -77,7 +56,7 @@ describe('app-dir root layout', () => {
describe
(
'Should do a mpa navigation when switching root layout'
,
()
=>
{
describe
(
'Should do a mpa navigation when switching root layout'
,
()
=>
{
it
(
'should work with basic routes'
,
async
()
=>
{
it
(
'should work with basic routes'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/basic-route'
)
const
browser
=
await
next
.
browser
(
'/basic-route'
)
expect
(
await
browser
.
elementById
(
'basic-route'
).
text
()).
toBe
(
expect
(
await
browser
.
elementById
(
'basic-route'
).
text
()).
toBe
(
'Basic route'
'Basic route'
...
@@ -100,7 +79,7 @@ describe('app-dir root layout', () => {
...
@@ -100,7 +79,7 @@ describe('app-dir root layout', () => {
})
})
it
(
'should work with route groups'
,
async
()
=>
{
it
(
'should work with route groups'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/route-group'
)
const
browser
=
await
next
.
browser
(
'/route-group'
)
expect
(
await
browser
.
elementById
(
'route-group'
).
text
()).
toBe
(
expect
(
await
browser
.
elementById
(
'route-group'
).
text
()).
toBe
(
'Route group'
'Route group'
...
@@ -126,7 +105,7 @@ describe('app-dir root layout', () => {
...
@@ -126,7 +105,7 @@ describe('app-dir root layout', () => {
})
})
it
(
'should work with parallel routes'
,
async
()
=>
{
it
(
'should work with parallel routes'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/with-parallel-routes'
)
const
browser
=
await
next
.
browser
(
'/with-parallel-routes'
)
expect
(
await
browser
.
elementById
(
'parallel-one'
).
text
()).
toBe
(
'One'
)
expect
(
await
browser
.
elementById
(
'parallel-one'
).
text
()).
toBe
(
'One'
)
expect
(
await
browser
.
elementById
(
'parallel-two'
).
text
()).
toBe
(
'Two'
)
expect
(
await
browser
.
elementById
(
'parallel-two'
).
text
()).
toBe
(
'Two'
)
...
@@ -148,7 +127,7 @@ describe('app-dir root layout', () => {
...
@@ -148,7 +127,7 @@ describe('app-dir root layout', () => {
})
})
it
(
'should work with dynamic routes'
,
async
()
=>
{
it
(
'should work with dynamic routes'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/dynamic/first'
)
const
browser
=
await
next
.
browser
(
'/dynamic/first'
)
expect
(
await
browser
.
elementById
(
'dynamic-first'
).
text
()).
toBe
(
expect
(
await
browser
.
elementById
(
'dynamic-first'
).
text
()).
toBe
(
'dynamic first'
'dynamic first'
...
@@ -171,7 +150,7 @@ describe('app-dir root layout', () => {
...
@@ -171,7 +150,7 @@ describe('app-dir root layout', () => {
})
})
it
(
'should work with dynamic catchall routes'
,
async
()
=>
{
it
(
'should work with dynamic catchall routes'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/dynamic-catchall/slug'
)
const
browser
=
await
next
.
browser
(
'/dynamic-catchall/slug'
)
expect
(
await
browser
.
elementById
(
'catchall-slug'
).
text
()).
toBe
(
expect
(
await
browser
.
elementById
(
'catchall-slug'
).
text
()).
toBe
(
'catchall slug'
'catchall slug'
...
@@ -194,7 +173,7 @@ describe('app-dir root layout', () => {
...
@@ -194,7 +173,7 @@ describe('app-dir root layout', () => {
})
})
it
(
'should work with static routes'
,
async
()
=>
{
it
(
'should work with static routes'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/static-mpa-navigation/slug1'
)
const
browser
=
await
next
.
browser
(
'/static-mpa-navigation/slug1'
)
expect
(
await
browser
.
elementById
(
'static-slug1'
).
text
()).
toBe
(
expect
(
await
browser
.
elementById
(
'static-slug1'
).
text
()).
toBe
(
'static slug1'
'static slug1'
...
@@ -216,4 +195,5 @@ describe('app-dir root layout', () => {
...
@@ -216,4 +195,5 @@ describe('app-dir root layout', () => {
expect
(
await
browser
.
eval
(
'window.__TEST_NO_RELOAD'
)).
toBeUndefined
()
expect
(
await
browser
.
eval
(
'window.__TEST_NO_RELOAD'
)).
toBeUndefined
()
})
})
})
})
})
}
)
test/e2e/app-dir/rsc-basic.test.ts
View file @
7a2ec416
This diff is collapsed.
Click to expand it.
test/e2e/app-dir/rsc-errors.test.ts
View file @
7a2ec416
import
path
from
'path'
import
path
from
'path'
import
{
check
,
fetchViaHTTP
,
renderViaHTTP
}
from
'next-test-utils'
import
{
check
}
from
'next-test-utils'
import
{
createNext
,
FileRef
}
from
'e2e-utils'
import
{
createNextDescribe
}
from
'e2e-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
describe
(
'app dir - rsc errors'
,
()
=>
{
if
(
!
(
globalThis
as
any
).
isNextDev
)
{
let
next
:
NextInstance
const
{
isNextDeploy
,
isNextDev
}
=
global
as
any
if
(
isNextDeploy
)
{
it
(
'should skip tests for next-deploy and react 17'
,
()
=>
{})
return
}
if
(
!
isNextDev
)
{
it
(
'should skip tests for next-start'
,
()
=>
{})
it
(
'should skip tests for next-start'
,
()
=>
{})
return
}
else
{
}
createNextDescribe
(
'app dir - rsc errors'
,
beforeAll
(
async
()
=>
{
{
next
=
await
createNext
({
files
:
path
.
join
(
__dirname
,
'./rsc-errors'
),
files
:
new
FileRef
(
path
.
join
(
__dirname
,
'./rsc-errors'
)),
skipDeployment
:
true
,
dependencies
:
{
react
:
'latest'
,
'react-dom'
:
'latest'
,
},
},
})
({
next
})
=>
{
})
afterAll
(()
=>
next
.
destroy
())
it
(
'should throw an error when getServerSideProps is used'
,
async
()
=>
{
it
(
'should throw an error when getServerSideProps is used'
,
async
()
=>
{
const
pageFile
=
'app/client-with-errors/get-server-side-props/page.js'
const
pageFile
=
'app/client-with-errors/get-server-side-props/page.js'
const
content
=
await
next
.
readFile
(
pageFile
)
const
content
=
await
next
.
readFile
(
pageFile
)
...
@@ -35,15 +20,13 @@ describe('app dir - rsc errors', () => {
...
@@ -35,15 +20,13 @@ describe('app dir - rsc errors', () => {
'export function getServerSideProps'
'export function getServerSideProps'
)
)
await
next
.
patchFile
(
pageFile
,
uncomment
)
await
next
.
patchFile
(
pageFile
,
uncomment
)
const
res
=
await
fetchViaHTTP
(
const
res
=
await
next
.
fetch
(
next
.
url
,
'/client-with-errors/get-server-side-props'
'/client-with-errors/get-server-side-props'
)
)
await
next
.
patchFile
(
pageFile
,
content
)
await
next
.
patchFile
(
pageFile
,
content
)
await
check
(
async
()
=>
{
await
check
(
async
()
=>
{
const
{
status
}
=
await
fetchViaHTTP
(
const
{
status
}
=
await
next
.
fetch
(
next
.
url
,
'/client-with-errors/get-server-side-props'
'/client-with-errors/get-server-side-props'
)
)
return
status
return
status
...
@@ -63,14 +46,10 @@ describe('app dir - rsc errors', () => {
...
@@ -63,14 +46,10 @@ describe('app dir - rsc errors', () => {
'export function getStaticProps'
'export function getStaticProps'
)
)
await
next
.
patchFile
(
pageFile
,
uncomment
)
await
next
.
patchFile
(
pageFile
,
uncomment
)
const
res
=
await
fetchViaHTTP
(
const
res
=
await
next
.
fetch
(
'/client-with-errors/get-static-props'
)
next
.
url
,
'/client-with-errors/get-static-props'
)
await
next
.
patchFile
(
pageFile
,
content
)
await
next
.
patchFile
(
pageFile
,
content
)
await
check
(
async
()
=>
{
await
check
(
async
()
=>
{
const
{
status
}
=
await
fetchViaHTTP
(
const
{
status
}
=
await
next
.
fetch
(
next
.
url
,
'/client-with-errors/get-static-props'
'/client-with-errors/get-static-props'
)
)
return
status
return
status
...
@@ -83,17 +62,14 @@ describe('app dir - rsc errors', () => {
...
@@ -83,17 +62,14 @@ describe('app dir - rsc errors', () => {
})
})
it
(
'should error for styled-jsx imports on server side'
,
async
()
=>
{
it
(
'should error for styled-jsx imports on server side'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/server-with-errors/styled-jsx'
)
const
html
=
await
next
.
render
(
'/server-with-errors/styled-jsx'
)
expect
(
html
).
toContain
(
expect
(
html
).
toContain
(
'This module cannot be imported from a Server Component module. It should only be used from a Client Component.'
'This module cannot be imported from a Server Component module. It should only be used from a Client Component.'
)
)
})
})
it
(
'should error when page component export is not valid'
,
async
()
=>
{
it
(
'should error when page component export is not valid'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
const
html
=
await
next
.
render
(
'/server-with-errors/page-export'
)
next
.
url
,
'/server-with-errors/page-export'
)
expect
(
html
).
toContain
(
expect
(
html
).
toContain
(
'The default export is not a React Component in page:'
'The default export is not a React Component in page:'
)
)
...
@@ -104,11 +80,11 @@ describe('app dir - rsc errors', () => {
...
@@ -104,11 +80,11 @@ describe('app dir - rsc errors', () => {
const
content
=
await
next
.
readFile
(
pageFile
)
const
content
=
await
next
.
readFile
(
pageFile
)
const
uncomment
=
content
.
replace
(
"// 'use client'"
,
"'use client'"
)
const
uncomment
=
content
.
replace
(
"// 'use client'"
,
"'use client'"
)
await
next
.
patchFile
(
pageFile
,
uncomment
)
await
next
.
patchFile
(
pageFile
,
uncomment
)
const
res
=
await
fetchViaHTTP
(
next
.
url
,
'/swc/use-client'
)
const
res
=
await
next
.
fetch
(
'/swc/use-client'
)
await
next
.
patchFile
(
pageFile
,
content
)
await
next
.
patchFile
(
pageFile
,
content
)
await
check
(
async
()
=>
{
await
check
(
async
()
=>
{
const
{
status
}
=
await
fetchViaHTTP
(
next
.
url
,
'/swc/use-client'
)
const
{
status
}
=
await
next
.
fetch
(
'/swc/use-client'
)
return
status
return
status
},
/200/
)
},
/200/
)
...
@@ -117,4 +93,6 @@ describe('app dir - rsc errors', () => {
...
@@ -117,4 +93,6 @@ describe('app dir - rsc errors', () => {
'directive must be placed before other expressions'
'directive must be placed before other expressions'
)
)
})
})
})
}
)
}
test/e2e/app-dir/standalone.test.ts
View file @
7a2ec416
import
{
createNext
,
FileRef
}
from
'e2e-utils'
import
{
createNextDescribe
,
FileRef
}
from
'e2e-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
fs
from
'fs-extra'
import
fs
from
'fs-extra'
import
os
from
'os'
import
os
from
'os'
import
path
from
'path'
import
path
from
'path'
import
{
import
{
fetchViaHTTP
,
findPort
,
findPort
,
initNextServerScript
,
initNextServerScript
,
killApp
,
killApp
,
fetchViaHTTP
,
}
from
'next-test-utils'
}
from
'next-test-utils'
describe
(
'output: standalone with app dir'
,
()
=>
{
if
(
!
(
globalThis
as
any
).
isNextStart
)
{
let
next
:
NextInstance
if
(
!
(
global
as
any
).
isNextStart
)
{
it
(
'should skip for non-next start'
,
()
=>
{})
it
(
'should skip for non-next start'
,
()
=>
{})
return
}
else
{
}
createNextDescribe
(
'output: standalone with app dir'
,
beforeAll
(
async
()
=>
{
{
next
=
await
createNext
({
files
:
new
FileRef
(
path
.
join
(
__dirname
,
'app'
)),
files
:
new
FileRef
(
path
.
join
(
__dirname
,
'app'
)),
dependencies
:
{
dependencies
:
{
swr
:
'2.0.0-rc.0'
,
swr
:
'2.0.0-rc.0'
,
...
@@ -28,19 +23,16 @@ describe('output: standalone with app dir', () => {
...
@@ -28,19 +23,16 @@ describe('output: standalone with app dir', () => {
sass
:
'latest'
,
sass
:
'latest'
,
},
},
skipStart
:
true
,
skipStart
:
true
,
})
},
({
next
})
=>
{
beforeAll
(
async
()
=>
{
await
next
.
patchFile
(
await
next
.
patchFile
(
'next.config.js'
,
'next.config.js'
,
(
await
next
.
readFile
(
'next.config.js'
)).
replace
(
'// output'
,
'output'
)
(
await
next
.
readFile
(
'next.config.js'
)).
replace
(
'// output'
,
'output'
)
)
)
await
next
.
start
()
await
next
.
start
()
})
})
afterAll
(
async
()
=>
{
await
next
.
destroy
()
})
if
((
global
as
any
).
isNextStart
)
{
it
(
'should handle trace files correctly for route groups (nodejs only)'
,
async
()
=>
{
it
(
'should handle trace files correctly for route groups (nodejs only)'
,
async
()
=>
{
expect
(
next
.
cliOutput
).
not
.
toContain
(
'Failed to copy traced files'
)
expect
(
next
.
cliOutput
).
not
.
toContain
(
'Failed to copy traced files'
)
const
serverDirPath
=
path
.
join
(
const
serverDirPath
=
path
.
join
(
...
@@ -67,10 +59,12 @@ describe('output: standalone with app dir', () => {
...
@@ -67,10 +59,12 @@ describe('output: standalone with app dir', () => {
}
}
}
}
})
})
}
it
(
'should work correctly with output standalone'
,
async
()
=>
{
it
(
'should work correctly with output standalone'
,
async
()
=>
{
const
tmpFolder
=
path
.
join
(
os
.
tmpdir
(),
'next-standalone-'
+
Date
.
now
())
const
tmpFolder
=
path
.
join
(
os
.
tmpdir
(),
'next-standalone-'
+
Date
.
now
()
)
await
fs
.
move
(
path
.
join
(
next
.
testDir
,
'.next/standalone'
),
tmpFolder
)
await
fs
.
move
(
path
.
join
(
next
.
testDir
,
'.next/standalone'
),
tmpFolder
)
let
server
:
any
let
server
:
any
...
@@ -111,4 +105,6 @@ describe('output: standalone with app dir', () => {
...
@@ -111,4 +105,6 @@ describe('output: standalone with app dir', () => {
await
fs
.
remove
(
tmpFolder
)
await
fs
.
remove
(
tmpFolder
)
}
}
})
})
})
}
)
}
test/e2e/app-dir/trailingslash.test.ts
View file @
7a2ec416
import
{
createNext
,
FileRef
}
from
'e2e-utils'
import
{
createNextDescribe
}
from
'e2e-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
{
fetchViaHTTP
,
renderViaHTTP
}
from
'next-test-utils'
import
path
from
'path'
import
path
from
'path'
import
cheerio
from
'cheerio'
import
webdriver
from
'next-webdriver'
describe
(
'app-dir trailingSlash handling'
,
()
=>
{
createNextDescribe
(
if
((
global
as
any
).
isNextDeploy
)
{
'app-dir trailingSlash handling'
,
it
(
'should skip next deploy for now'
,
()
=>
{})
{
return
files
:
path
.
join
(
__dirname
,
'trailingslash'
),
}
skipDeployment
:
true
,
let
next
:
NextInstance
beforeAll
(
async
()
=>
{
next
=
await
createNext
({
files
:
new
FileRef
(
path
.
join
(
__dirname
,
'trailingslash'
)),
dependencies
:
{
react
:
'latest'
,
'react-dom'
:
'latest'
,
},
},
skipStart
:
true
,
({
next
})
=>
{
})
await
next
.
start
()
})
afterAll
(()
=>
next
.
destroy
())
it
(
'should redirect route when requesting it directly'
,
async
()
=>
{
it
(
'should redirect route when requesting it directly'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
const
res
=
await
next
.
fetch
(
next
.
url
,
'/a'
,
'/a'
,
{},
{},
{
{
...
@@ -41,22 +21,22 @@ describe('app-dir trailingSlash handling', () => {
...
@@ -41,22 +21,22 @@ describe('app-dir trailingSlash handling', () => {
})
})
it
(
'should render link with trailing slash'
,
async
()
=>
{
it
(
'should render link with trailing slash'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/'
)
const
$
=
await
next
.
render$
(
'/'
)
const
$
=
cheerio
.
load
(
html
)
expect
(
$
(
'#to-a-trailing-slash'
).
attr
(
'href'
)).
toBe
(
'/a/'
)
expect
(
$
(
'#to-a-trailing-slash'
).
attr
(
'href'
)).
toBe
(
'/a/'
)
})
})
it
(
'should redirect route when requesting it directly by browser'
,
async
()
=>
{
it
(
'should redirect route when requesting it directly by browser'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/a'
)
const
browser
=
await
next
.
browser
(
'/a'
)
expect
(
await
browser
.
waitForElementByCss
(
'#a-page'
).
text
()).
toBe
(
'A page'
)
expect
(
await
browser
.
waitForElementByCss
(
'#a-page'
).
text
()).
toBe
(
'A page'
)
})
})
it
(
'should redirect route when clicking link'
,
async
()
=>
{
it
(
'should redirect route when clicking link'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/'
)
const
browser
=
await
next
.
browser
(
'/'
)
await
browser
await
browser
.
elementByCss
(
'#to-a-trailing-slash'
)
.
elementByCss
(
'#to-a-trailing-slash'
)
.
click
()
.
click
()
.
waitForElementByCss
(
'#a-page'
)
.
waitForElementByCss
(
'#a-page'
)
expect
(
await
browser
.
waitForElementByCss
(
'#a-page'
).
text
()).
toBe
(
'A page'
)
expect
(
await
browser
.
waitForElementByCss
(
'#a-page'
).
text
()).
toBe
(
'A page'
)
})
})
})
}
)
test/e2e/app-dir/vercel-analytics.test.ts
View file @
7a2ec416
...
@@ -2,7 +2,6 @@ import { createNext, FileRef } from 'e2e-utils'
...
@@ -2,7 +2,6 @@ import { createNext, FileRef } from 'e2e-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
{
check
}
from
'next-test-utils'
import
{
check
}
from
'next-test-utils'
import
path
from
'path'
import
path
from
'path'
import
webdriver
from
'next-webdriver'
describe
(
'vercel analytics'
,
()
=>
{
describe
(
'vercel analytics'
,
()
=>
{
const
isDev
=
(
global
as
any
).
isNextDev
const
isDev
=
(
global
as
any
).
isNextDev
...
@@ -48,7 +47,7 @@ describe('vercel analytics', () => {
...
@@ -48,7 +47,7 @@ describe('vercel analytics', () => {
it
(
'should send web vitals to Vercel analytics'
,
async
()
=>
{
it
(
'should send web vitals to Vercel analytics'
,
async
()
=>
{
let
eventsCount
=
0
let
eventsCount
=
0
let
countEvents
=
false
let
countEvents
=
false
const
browser
=
await
webdriver
(
next
.
url
,
'/client-nested'
,
{
const
browser
=
await
next
.
browser
(
'/client-nested'
,
{
beforePageLoad
(
page
)
{
beforePageLoad
(
page
)
{
page
.
route
(
page
.
route
(
'https://vitals.vercel-insights.com/v1/vitals'
,
'https://vitals.vercel-insights.com/v1/vitals'
,
...
...
test/e2e/app-dir/with-babel.test.ts
View file @
7a2ec416
import
{
createNext
,
FileRef
}
from
'e2e-utils'
import
{
createNextDescribe
}
from
'e2e-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
{
renderViaHTTP
}
from
'next-test-utils'
import
path
from
'path'
import
path
from
'path'
import
cheerio
from
'cheerio'
describe
(
'with babel'
,
()
=>
{
createNextDescribe
(
if
((
global
as
any
).
isNextDeploy
)
{
'with babel'
,
it
(
'should skip next deploy for now'
,
()
=>
{})
{
return
files
:
path
.
join
(
__dirname
,
'with-babel'
),
}
skipDeployment
:
true
,
let
next
:
NextInstance
beforeAll
(
async
()
=>
{
next
=
await
createNext
({
files
:
new
FileRef
(
path
.
join
(
__dirname
,
'with-babel'
)),
dependencies
:
{
react
:
'latest'
,
'react-dom'
:
'latest'
,
},
},
})
({
next
})
=>
{
})
afterAll
(()
=>
next
.
destroy
())
it
(
'should support babel in app dir'
,
async
()
=>
{
it
(
'should support babel in app dir'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
next
.
url
,
'/'
)
const
$
=
await
next
.
render$
(
'/'
)
const
$
=
cheerio
.
load
(
html
)
expect
(
$
(
'h1'
).
text
()).
toBe
(
'hello'
)
expect
(
$
(
'h1'
).
text
()).
toBe
(
'hello'
)
})
})
})
}
)
test/e2e/transpile-packages/index.test.ts
View file @
7a2ec416
...
@@ -35,8 +35,7 @@ describe('transpile packages', () => {
...
@@ -35,8 +35,7 @@ describe('transpile packages', () => {
afterAll
(()
=>
next
.
destroy
())
afterAll
(()
=>
next
.
destroy
())
const
{
isNextDeploy
}
=
global
as
any
const
{
isNextDeploy
}
=
global
as
any
const
isReact17
=
process
.
env
.
NEXT_TEST_REACT_VERSION
===
'^17'
if
(
isNextDeploy
)
{
if
(
isNextDeploy
||
isReact17
)
{
it
(
'should skip tests for next-deploy and react 17'
,
()
=>
{})
it
(
'should skip tests for next-deploy and react 17'
,
()
=>
{})
return
return
}
}
...
...
test/lib/e2e-utils.ts
View file @
7a2ec416
...
@@ -221,7 +221,8 @@ export function createNextDescribe(
...
@@ -221,7 +221,8 @@ export function createNextDescribe(
const
nextProxy
=
new
Proxy
<
NextInstance
>
({}
as
NextInstance
,
{
const
nextProxy
=
new
Proxy
<
NextInstance
>
({}
as
NextInstance
,
{
get
:
function
(
_target
,
property
)
{
get
:
function
(
_target
,
property
)
{
return
next
[
property
]
const
prop
=
next
[
property
]
return
typeof
prop
===
'function'
?
prop
.
bind
(
next
)
:
prop
},
},
})
})
fn
({
fn
({
...
...
test/lib/next-modes/base.ts
View file @
7a2ec416
...
@@ -364,6 +364,9 @@ export class NextInstance {
...
@@ -364,6 +364,9 @@ export class NextInstance {
public
async
readFile
(
filename
:
string
)
{
public
async
readFile
(
filename
:
string
)
{
return
fs
.
readFile
(
path
.
join
(
this
.
testDir
,
filename
),
'utf8'
)
return
fs
.
readFile
(
path
.
join
(
this
.
testDir
,
filename
),
'utf8'
)
}
}
public
async
readJSON
(
filename
:
string
)
{
return
fs
.
readJSON
(
path
.
join
(
this
.
testDir
,
filename
))
}
public
async
patchFile
(
filename
:
string
,
content
:
string
)
{
public
async
patchFile
(
filename
:
string
,
content
:
string
)
{
const
outputPath
=
path
.
join
(
this
.
testDir
,
filename
)
const
outputPath
=
path
.
join
(
this
.
testDir
,
filename
)
await
fs
.
ensureDir
(
path
.
dirname
(
outputPath
))
await
fs
.
ensureDir
(
path
.
dirname
(
outputPath
))
...
...
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