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
d40f2723
Commit
d40f2723
authored
Oct 20, 2018
by
Henrik Wenz
Committed by
Tim Neutkens
Oct 20, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add size-limit test (#5339)
parent
1b8f5655
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
91 additions
and
0 deletions
+91
-0
next.config.js
test/integration/size-limit/next.config.js
+6
-0
about.js
test/integration/size-limit/pages/about.js
+5
-0
index.js
test/integration/size-limit/pages/index.js
+9
-0
index.test.js
test/integration/size-limit/test/index.test.js
+71
-0
No files found.
test/integration/size-limit/next.config.js
0 → 100644
View file @
d40f2723
module
.
exports
=
{
onDemandEntries
:
{
// Make sure entries are not getting disposed.
maxInactiveAge
:
1000
*
60
*
60
}
}
test/integration/size-limit/pages/about.js
0 → 100644
View file @
d40f2723
export
default
()
=>
(
<
div
>
About
<
/div
>
)
test/integration/size-limit/pages/index.js
0 → 100644
View file @
d40f2723
import
Link
from
'next/link'
export
default
()
=>
(
<
div
>
Size
-
Limit
Page
<
br
/>
<
Link
href
=
'/about'
><
a
>
about
<
/a></
Link
>
<
/div
>
)
test/integration/size-limit/test/index.test.js
0 → 100644
View file @
d40f2723
/* eslint-env jest */
/* global jasmine */
import
{
nextBuild
,
nextServer
,
startApp
,
stopApp
}
from
'next-test-utils'
import
{
join
}
from
'path'
import
cheerio
from
'cheerio'
import
fetch
from
'node-fetch'
jasmine
.
DEFAULT_TIMEOUT_INTERVAL
=
1000
*
60
*
5
let
responseSizes
describe
(
'Production response size'
,
()
=>
{
beforeAll
(
async
()
=>
{
const
dir
=
join
(
__dirname
,
'../'
)
// Build next app
await
nextBuild
(
dir
)
// Start next app
const
server
=
await
startApp
(
nextServer
({
dir
,
dev
:
false
,
quiet
:
true
})
)
// Get the html document
const
baseUrl
=
`http://localhost:
${
server
.
address
().
port
}
`
const
htmlResponse
=
await
fetch
(
baseUrl
)
// Find all script urls
const
html
=
await
htmlResponse
.
text
()
const
$
=
cheerio
.
load
(
html
)
const
scriptsUrls
=
$
(
'script[src]'
)
.
map
((
i
,
el
)
=>
$
(
el
).
attr
(
'src'
))
.
get
()
.
map
(
path
=>
`
${
baseUrl
}${
path
}
`
)
// Measure the html document and all scripts
const
resourceUrls
=
[
baseUrl
,
...
scriptsUrls
]
// Fetch all resources and get their size (bytes)
responseSizes
=
await
Promise
.
all
(
resourceUrls
.
map
(
async
(
url
)
=>
{
const
context
=
await
fetch
(
url
).
then
(
res
=>
res
.
text
())
return
{
url
,
bytes
:
context
.
length
}
}))
// Clean up
await
stopApp
(
server
)
})
it
(
'should not increase the overall response size'
,
async
()
=>
{
const
responseSizeBytes
=
responseSizes
.
reduce
(
(
accumulator
,
responseSizeObj
)
=>
accumulator
+
responseSizeObj
.
bytes
,
0
)
const
responseSizeKilobytes
=
Math
.
ceil
(
responseSizeBytes
/
1024
)
console
.
log
(
`Response Sizes:\n
${
responseSizes
.
map
(
obj
=>
`
${
obj
.
url
}
:
${
obj
.
bytes
}
(bytes)`
).
join
(
'
\
n'
)}
\nOverall:
${
responseSizeKilobytes
}
KB`
)
// These numbers are without gzip compression!
expect
(
responseSizeKilobytes
).
toBeLessThanOrEqual
(
203
)
// Kilobytes
})
})
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