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
33067a58
Unverified
Commit
33067a58
authored
Sep 02, 2018
by
Tim Neutkens
Committed by
GitHub
Sep 02, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix inconsistency in dynamic tests (#5071)
parent
442ec793
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
151 additions
and
10 deletions
+151
-10
dynamic.js
test/integration/basic/test/dynamic.js
+0
-6
dynamic.js
test/integration/production/test/dynamic.js
+141
-0
index.test.js
test/integration/production/test/index.test.js
+1
-1
next-test-utils.js
test/lib/next-test-utils.js
+9
-3
No files found.
test/integration/basic/test/dynamic.js
View file @
33067a58
...
@@ -136,11 +136,5 @@ export default (context, render) => {
...
@@ -136,11 +136,5 @@ export default (context, render) => {
browser
.
close
()
browser
.
close
()
})
})
})
})
// describe('with browser', () => {
// describe('with bundle', () => {
// })
})
})
}
}
test/integration/production/test/dynamic.js
0 → 100644
View file @
33067a58
/* global describe, it, expect */
import
webdriver
from
'next-webdriver'
import
cheerio
from
'cheerio'
import
{
waitFor
,
check
}
from
'next-test-utils'
// These tests are similar to ../../basic/test/dynamic.js
export
default
(
context
,
render
)
=>
{
async
function
get
$
(
path
,
query
)
{
const
html
=
await
render
(
path
,
query
)
return
cheerio
.
load
(
html
)
}
describe
(
'Dynamic import'
,
()
=>
{
describe
(
'default behavior'
,
()
=>
{
it
(
'should render dynamic import components'
,
async
()
=>
{
const
$
=
await
get
$
(
'/dynamic/ssr'
)
expect
(
$
(
'body'
).
text
()).
toMatch
(
/Hello World 1/
)
})
it
(
'should render even there are no physical chunk exists'
,
async
()
=>
{
let
browser
try
{
browser
=
await
webdriver
(
context
.
appPort
,
'/dynamic/no-chunk'
)
await
check
(()
=>
browser
.
elementByCss
(
'body'
).
text
(),
/Welcome, normal/
)
await
check
(()
=>
browser
.
elementByCss
(
'body'
).
text
(),
/Welcome, dynamic/
)
}
finally
{
if
(
browser
)
{
browser
.
close
()
}
}
})
})
describe
(
'ssr:false option'
,
()
=>
{
it
(
'Should render loading on the server side'
,
async
()
=>
{
const
$
=
await
get
$
(
'/dynamic/no-ssr'
)
expect
(
$
(
'p'
).
text
()).
toBe
(
'loading...'
)
})
it
(
'should render the component on client side'
,
async
()
=>
{
let
browser
try
{
browser
=
await
webdriver
(
context
.
appPort
,
'/dynamic/no-ssr'
)
await
check
(()
=>
browser
.
elementByCss
(
'body'
).
text
(),
/Hello World 1/
)
}
finally
{
if
(
browser
)
{
browser
.
close
()
}
}
})
})
describe
(
'custom loading'
,
()
=>
{
it
(
'should render custom loading on the server side when `ssr:false` and `loading` is provided'
,
async
()
=>
{
const
$
=
await
get
$
(
'/dynamic/no-ssr-custom-loading'
)
expect
(
$
(
'p'
).
text
()).
toBe
(
'LOADING'
)
})
it
(
'should render the component on client side'
,
async
()
=>
{
let
browser
try
{
browser
=
await
webdriver
(
context
.
appPort
,
'/dynamic/no-ssr-custom-loading'
)
await
check
(()
=>
browser
.
elementByCss
(
'body'
).
text
(),
/Hello World 1/
)
}
finally
{
if
(
browser
)
{
browser
.
close
()
}
}
})
})
describe
(
'Import mapping'
,
()
=>
{
it
(
'should render dynamic imports bundle'
,
async
()
=>
{
const
$
=
await
get
$
(
'/dynamic/bundle'
)
const
bodyText
=
$
(
'body'
).
text
()
expect
(
/Dynamic Bundle/
.
test
(
bodyText
)).
toBe
(
true
)
expect
(
/Hello World 1/
.
test
(
bodyText
)).
toBe
(
true
)
expect
(
/Hello World 2/
.
test
(
bodyText
)).
toBe
(
false
)
})
it
(
'should render dynamic imports bundle with additional components'
,
async
()
=>
{
const
$
=
await
get
$
(
'/dynamic/bundle?showMore=1'
)
const
bodyText
=
$
(
'body'
).
text
()
expect
(
/Dynamic Bundle/
.
test
(
bodyText
)).
toBe
(
true
)
expect
(
/Hello World 1/
.
test
(
bodyText
)).
toBe
(
true
)
expect
(
/Hello World 2/
.
test
(
bodyText
)).
toBe
(
true
)
})
it
(
'should render components'
,
async
()
=>
{
const
browser
=
await
webdriver
(
context
.
appPort
,
'/dynamic/bundle'
)
while
(
true
)
{
const
bodyText
=
await
browser
.
elementByCss
(
'body'
).
text
()
if
(
/Dynamic Bundle/
.
test
(
bodyText
)
&&
/Hello World 1/
.
test
(
bodyText
)
&&
!
(
/Hello World 2/
.
test
(
bodyText
))
)
break
await
waitFor
(
1000
)
}
browser
.
close
()
})
it
(
'should render support React context'
,
async
()
=>
{
const
browser
=
await
webdriver
(
context
.
appPort
,
'/dynamic/bundle'
)
while
(
true
)
{
const
bodyText
=
await
browser
.
elementByCss
(
'body'
).
text
()
if
(
/ZEIT Rocks/
.
test
(
bodyText
)
)
break
await
waitFor
(
1000
)
}
browser
.
close
()
})
it
(
'should load new components and render for prop changes'
,
async
()
=>
{
const
browser
=
await
webdriver
(
context
.
appPort
,
'/dynamic/bundle'
)
await
browser
.
waitForElementByCss
(
'#toggle-show-more'
)
.
elementByCss
(
'#toggle-show-more'
).
click
()
while
(
true
)
{
const
bodyText
=
await
browser
.
elementByCss
(
'body'
).
text
()
if
(
/Dynamic Bundle/
.
test
(
bodyText
)
&&
/Hello World 1/
.
test
(
bodyText
)
&&
/Hello World 2/
.
test
(
bodyText
)
)
break
await
waitFor
(
1000
)
}
browser
.
close
()
})
})
})
}
test/integration/production/test/index.test.js
View file @
33067a58
...
@@ -13,7 +13,7 @@ import {
...
@@ -13,7 +13,7 @@ import {
}
from
'next-test-utils'
}
from
'next-test-utils'
import
webdriver
from
'next-webdriver'
import
webdriver
from
'next-webdriver'
import
fetch
from
'node-fetch'
import
fetch
from
'node-fetch'
import
dynamicImportTests
from
'.
./../basic/test
/dynamic'
import
dynamicImportTests
from
'./dynamic'
import
security
from
'./security'
import
security
from
'./security'
import
{
BUILD_MANIFEST
,
REACT_LOADABLE_MANIFEST
}
from
'next/constants'
import
{
BUILD_MANIFEST
,
REACT_LOADABLE_MANIFEST
}
from
'next/constants'
...
...
test/lib/next-test-utils.js
View file @
33067a58
...
@@ -152,12 +152,18 @@ export async function startStaticServer (dir) {
...
@@ -152,12 +152,18 @@ export async function startStaticServer (dir) {
export
async
function
check
(
contentFn
,
regex
)
{
export
async
function
check
(
contentFn
,
regex
)
{
let
found
=
false
let
found
=
false
setTimeout
(()
=>
{
setTimeout
(
async
()
=>
{
if
(
found
)
{
if
(
found
)
{
return
return
}
}
console
.
error
(
'TIMED OUT CHECK: '
,
regex
)
let
content
throw
new
Error
(
'TIMED OUT'
)
try
{
content
=
await
contentFn
()
}
catch
(
err
)
{
console
.
error
(
'Error while getting content'
,
{
regex
})
}
console
.
error
(
'TIMED OUT CHECK: '
,
{
regex
,
content
})
throw
new
Error
(
'TIMED OUT: '
+
regex
+
'
\
n
\
n'
+
content
)
},
1000
*
30
)
},
1000
*
30
)
while
(
!
found
)
{
while
(
!
found
)
{
try
{
try
{
...
...
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