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
9386ba29
Unverified
Commit
9386ba29
authored
May 19, 2020
by
Joe Haddad
Committed by
GitHub
May 19, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stabilize `config` tests (#13116)
parent
f7bdf29e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
65 deletions
+84
-65
index.test.js
test/integration/config/test/index.test.js
+84
-48
next-test-utils.js
test/lib/next-test-utils.js
+0
-17
No files found.
test/integration/config/test/index.test.js
View file @
9386ba29
/* eslint-env jest */
import
{
join
}
from
'path'
import
cheerio
from
'cheerio'
import
{
readFileSync
,
writeFileSync
}
from
'fs'
import
{
renderViaHTTP
,
check
,
File
,
findPort
,
launchApp
,
killApp
,
File
,
checkExpectations
,
launchApp
,
renderViaHTTP
,
}
from
'next-test-utils'
import
fetch
from
'node-fetch'
import
cheerio
from
'cheerio'
import
webdriver
from
'next-webdriver'
import
{
readFileSync
,
writeFileSync
}
from
'fs'
import
fetch
from
'node-fetch'
import
{
join
}
from
'path'
const
context
=
{}
jest
.
setTimeout
(
1000
*
60
*
5
)
...
...
@@ -50,10 +50,15 @@ describe('Configuration', () => {
let
browser
try
{
browser
=
await
webdriver
(
context
.
appPort
,
'/webpack-css'
)
const
fontSize
=
await
browser
.
elementByCss
(
'.hello-world'
)
.
getComputedCss
(
'font-size'
)
expect
(
fontSize
).
toBe
(
'100px'
)
await
check
(
()
=>
browser
.
elementByCss
(
'.hello-world'
).
getComputedCss
(
'font-size'
),
{
test
(
content
)
{
return
content
===
'100px'
},
}
)
}
finally
{
if
(
browser
)
{
await
browser
.
close
()
...
...
@@ -65,10 +70,17 @@ describe('Configuration', () => {
let
browser
try
{
browser
=
await
webdriver
(
context
.
appPort
,
'/webpack-css'
)
const
backgroundColor
=
await
browser
.
elementByCss
(
'.hello-world'
)
.
getComputedCss
(
'background-color'
)
expect
(
backgroundColor
).
toBe
(
'rgba(0, 0, 255, 1)'
)
await
check
(
()
=>
browser
.
elementByCss
(
'.hello-world'
)
.
getComputedCss
(
'background-color'
),
{
test
(
content
)
{
return
content
===
'rgba(0, 0, 255, 1)'
},
}
)
}
finally
{
if
(
browser
)
{
await
browser
.
close
()
...
...
@@ -115,10 +127,19 @@ describe('Configuration', () => {
let
browser
try
{
browser
=
await
webdriver
(
context
.
appPort
,
'/webpack-css'
)
const
pTag
=
await
browser
.
elementByCss
(
'.hello-world'
)
const
initialFontSize
=
await
pTag
.
getComputedCss
(
'font-size'
)
expect
(
initialFontSize
).
toBe
(
'100px'
)
await
check
(
async
()
=>
{
const
pTag
=
await
browser
.
elementByCss
(
'.hello-world'
)
const
initialFontSize
=
await
pTag
.
getComputedCss
(
'font-size'
)
return
initialFontSize
},
{
test
(
content
)
{
return
content
===
'100px'
},
}
)
const
pagePath
=
join
(
__dirname
,
...
...
@@ -134,24 +155,30 @@ describe('Configuration', () => {
writeFileSync
(
pagePath
,
editedContent
,
'utf8'
)
try
{
await
checkExpectations
(
async
()
=>
{
// Check whether the this page has reloaded or not.
const
editedFontSize
=
await
browser
.
elementByCss
(
'.hello-world'
)
.
getComputedCss
(
'font-size'
)
expect
(
editedFontSize
).
toBe
(
'200px'
)
})
// Check whether the this page has reloaded or not.
await
check
(
()
=>
browser
.
elementByCss
(
'.hello-world'
).
getComputedCss
(
'font-size'
),
{
test
(
content
)
{
return
content
===
'200px'
},
}
)
}
finally
{
// Finally is used so that we revert the content back to the original regardless of the test outcome
// restore the about page content.
writeFileSync
(
pagePath
,
originalContent
,
'utf8'
)
await
checkExpectations
(
async
()
=>
{
// This also make sure that the change is reverted when the etst ends
const
editedFontSize
=
await
browser
.
elementByCss
(
'.hello-world'
)
.
getComputedCss
(
'font-size'
)
expect
(
editedFontSize
).
toBe
(
'100px'
)
})
// This also make sure that the change is reverted when the test ends
await
check
(
()
=>
browser
.
elementByCss
(
'.hello-world'
).
getComputedCss
(
'font-size'
),
{
test
(
content
)
{
return
content
===
'100px'
},
}
)
}
}
finally
{
if
(
browser
)
{
...
...
@@ -167,26 +194,35 @@ describe('Configuration', () => {
let
browser
try
{
browser
=
await
webdriver
(
context
.
appPort
,
'/webpack-css'
)
expect
(
await
browser
.
elementByCss
(
'.hello-world'
).
getComputedCss
(
'color'
)
).
toBe
(
'rgba(255, 255, 0, 1)'
)
await
check
(
()
=>
browser
.
elementByCss
(
'.hello-world'
).
getComputedCss
(
'color'
),
{
test
(
content
)
{
return
content
===
'rgba(255, 255, 0, 1)'
},
}
)
try
{
file
.
replace
(
'yellow'
,
'red'
)
await
checkExpectations
(
async
()
=>
{
const
color
=
await
browser
.
elementByCss
(
'.hello-world'
)
.
getComputedCss
(
'color'
)
expect
(
color
).
toBe
(
'rgba(255, 0, 0, 1)'
)
})
await
check
(
()
=>
browser
.
elementByCss
(
'.hello-world'
).
getComputedCss
(
'color'
),
{
test
(
content
)
{
return
content
===
'rgba(255, 0, 0, 1)'
},
}
)
}
finally
{
file
.
restore
()
await
checkExpectations
(
async
()
=>
{
const
color
=
await
browser
.
elementByCss
(
'.hello-world'
)
.
getComputedCss
(
'color'
)
expect
(
color
).
toBe
(
'rgba(255, 255, 0, 1)'
)
})
await
check
(
()
=>
browser
.
elementByCss
(
'.hello-world'
).
getComputedCss
(
'color'
),
{
test
(
content
)
{
return
content
===
'rgba(255, 255, 0, 1)'
},
}
)
}
}
finally
{
if
(
browser
)
{
...
...
test/lib/next-test-utils.js
View file @
9386ba29
...
...
@@ -365,23 +365,6 @@ export async function check(contentFn, regex, hardError = true) {
return
false
}
// Runs the provided expectations periodically until they pass or time out
export
async
function
checkExpectations
(
runExpectations
)
{
const
interval
=
250
const
timeout
=
30000
const
startTime
=
Date
.
now
()
while
(
true
)
{
try
{
return
await
runExpectations
()
}
catch
(
err
)
{
if
(
Date
.
now
()
-
startTime
>
timeout
)
{
throw
err
}
}
await
waitFor
(
interval
)
}
}
export
class
File
{
constructor
(
path
)
{
this
.
path
=
path
...
...
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