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
7b193f1a
Commit
7b193f1a
authored
May 09, 2017
by
Arunoda Susiripala
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add basic test setup
parent
e8ff53f5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
234 additions
and
7 deletions
+234
-7
.gitignore
.gitignore
+1
-1
package.json
package.json
+1
-0
index.test.js
test/integration/static/test/index.test.js
+45
-0
next-test-utils.js
test/lib/next-test-utils.js
+15
-1
yarn.lock
yarn.lock
+172
-5
No files found.
.gitignore
View file @
7b193f1a
...
...
@@ -6,7 +6,7 @@ dist
node_modules
# logs
npm-debug
.log
*
.log
# coverage
.nyc_output
...
...
package.json
View file @
7b193f1a
...
...
@@ -105,6 +105,7 @@
"
chromedriver
"
:
"2.29.0"
,
"
coveralls
"
:
"2.13.1"
,
"
cross-env
"
:
"4.0.0"
,
"
express
"
:
"4.15.2"
,
"
fly
"
:
"2.0.6"
,
"
fly-babel
"
:
"2.1.1"
,
"
fly-clear
"
:
"1.0.1"
,
...
...
test/integration/static/test/index.test.js
0 → 100644
View file @
7b193f1a
/* global jasmine, describe, it, expect, beforeAll, afterAll */
import
{
join
}
from
'path'
import
{
nextBuild
,
nextExport
,
renderViaHTTP
,
startStaticServer
,
stopApp
}
from
'next-test-utils'
import
webdriver
from
'next-webdriver'
jasmine
.
DEFAULT_TIMEOUT_INTERVAL
=
40000
const
appDir
=
join
(
__dirname
,
'../'
)
const
context
=
{}
describe
(
'Static Export'
,
()
=>
{
beforeAll
(
async
()
=>
{
const
outdir
=
join
(
appDir
,
'.out'
)
await
nextBuild
(
appDir
)
await
nextExport
(
appDir
,
{
outdir
})
context
.
server
=
await
startStaticServer
(
join
(
appDir
,
'.out'
))
context
.
port
=
context
.
server
.
address
().
port
})
afterAll
(()
=>
stopApp
(
context
.
server
))
describe
(
'Render via SSR'
,
()
=>
{
it
(
'should render the home page'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
context
.
port
,
'/'
)
expect
(
html
).
toMatch
(
/This is the home page/
)
})
})
describe
(
'Render via browser'
,
()
=>
{
it
(
'should render the home page'
,
async
()
=>
{
const
browser
=
await
webdriver
(
context
.
port
,
'/'
)
const
text
=
await
browser
.
elementByCss
(
'#home-page p'
).
text
()
expect
(
text
).
toBe
(
'This is the home page'
)
browser
.
close
()
})
})
})
test/lib/next-test-utils.js
View file @
7b193f1a
import
fetch
from
'node-fetch'
import
qs
from
'querystring'
import
http
from
'http'
import
express
from
'express'
import
server
from
'../../dist/server/next'
import
build
from
'../../dist/server/build'
import
_export
from
'../../dist/server/export'
import
_pkg
from
'../../package.json'
export
const
nextServer
=
server
export
const
nextBuild
=
build
export
const
nextExport
=
_export
export
const
pkg
=
_pkg
export
function
renderViaAPI
(
app
,
pathname
,
query
=
{})
{
...
...
@@ -31,7 +34,9 @@ export async function startApp (app) {
}
export
async
function
stopApp
(
app
)
{
await
server
.
__app
.
close
()
if
(
server
.
__app
)
{
await
server
.
__app
.
close
()
}
await
promiseCall
(
server
,
'close'
)
}
...
...
@@ -52,3 +57,12 @@ function promiseCall (obj, method, ...args) {
export
function
waitFor
(
millis
)
{
return
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
millis
))
}
export
async
function
startStaticServer
(
dir
)
{
const
app
=
express
()
const
server
=
http
.
createServer
(
app
)
app
.
use
(
express
.
static
(
dir
))
await
promiseCall
(
server
,
'listen'
)
return
server
}
yarn.lock
View file @
7b193f1a
This diff is collapsed.
Click to expand it.
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