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
64a9ae91
Unverified
Commit
64a9ae91
authored
Nov 10, 2019
by
Joe Haddad
Committed by
GitHub
Nov 10, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test CJS Import of `isomorphic-unfetch` (#9363)
parent
8dcec04b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
1 deletion
+57
-1
fetch-cjs.js
test/integration/serverless/pages/fetch-cjs.js
+29
-0
index.js
test/integration/serverless/pages/index.js
+3
-0
index.test.js
test/integration/serverless/test/index.test.js
+25
-1
No files found.
test/integration/serverless/pages/fetch-cjs.js
0 → 100644
View file @
64a9ae91
const
fetch
=
require
(
'isomorphic-unfetch'
)
const
React
=
require
(
'react'
)
export
default
class
extends
React
.
Component
{
static
async
getInitialProps
()
{
try
{
const
res
=
await
fetch
(
''
)
const
text
=
await
res
.
text
()
console
.
log
(
text
)
return
{
text
}
}
catch
(
err
)
{
if
(
err
.
message
.
includes
(
'is not a function'
))
{
return
{
failed
:
true
,
error
:
err
.
toString
()
}
}
return
{
error
:
err
.
toString
()
}
}
}
render
()
{
const
{
failed
,
error
,
text
}
=
this
.
props
return
(
<
div
className
=
'fetch-cjs-page'
>
{
failed
?
'failed'
:
''
}
{
error
}
<
div
id
=
'text'
>
{
text
}
<
/div
>
<
/div
>
)
}
}
test/integration/serverless/pages/index.js
View file @
64a9ae91
...
@@ -6,6 +6,9 @@ export default () => {
...
@@ -6,6 +6,9 @@ export default () => {
<
Link
href
=
'/fetch'
>
<
Link
href
=
'/fetch'
>
<
a
id
=
'fetchlink'
>
fetch
page
<
/a
>
<
a
id
=
'fetchlink'
>
fetch
page
<
/a
>
<
/Link
>
<
/Link
>
<
Link
href
=
'/fetch-cjs'
>
<
a
id
=
'fetchcjslink'
>
fetch
cjs
page
<
/a
>
<
/Link
>
<
/div
>
<
/div
>
)
)
}
}
test/integration/serverless/test/index.test.js
View file @
64a9ae91
...
@@ -111,7 +111,7 @@ describe('Serverless', () => {
...
@@ -111,7 +111,7 @@ describe('Serverless', () => {
const
browser
=
await
webdriver
(
appPort
,
'/'
)
const
browser
=
await
webdriver
(
appPort
,
'/'
)
try
{
try
{
const
text
=
await
browser
const
text
=
await
browser
.
elementByCss
(
'
a
'
)
.
elementByCss
(
'
#fetchlink
'
)
.
click
()
.
click
()
.
waitForElementByCss
(
'.fetch-page'
)
.
waitForElementByCss
(
'.fetch-page'
)
.
elementByCss
(
'#text'
)
.
elementByCss
(
'#text'
)
...
@@ -123,6 +123,30 @@ describe('Serverless', () => {
...
@@ -123,6 +123,30 @@ describe('Serverless', () => {
}
}
})
})
it
(
'should render correctly when importing isomorphic-unfetch CJS'
,
async
()
=>
{
const
url
=
`http://localhost:
${
appPort
}
/fetch-cjs`
const
res
=
await
fetch
(
url
)
expect
(
res
.
status
).
toBe
(
200
)
const
text
=
await
res
.
text
()
expect
(
text
.
includes
(
'failed'
)).
toBe
(
false
)
})
it
(
'should render correctly when importing isomorphic-unfetch CJS on the client side'
,
async
()
=>
{
const
browser
=
await
webdriver
(
appPort
,
'/'
)
try
{
const
text
=
await
browser
.
elementByCss
(
'#fetchcjslink'
)
.
click
()
.
waitForElementByCss
(
'.fetch-cjs-page'
)
.
elementByCss
(
'#text'
)
.
text
()
expect
(
text
).
toMatch
(
/fetch page/
)
}
finally
{
await
browser
.
close
()
}
})
it
(
'should not have combined client-side chunks'
,
()
=>
{
it
(
'should not have combined client-side chunks'
,
()
=>
{
expect
(
readdirSync
(
chunksDir
).
length
).
toBeGreaterThanOrEqual
(
2
)
expect
(
readdirSync
(
chunksDir
).
length
).
toBeGreaterThanOrEqual
(
2
)
const
buildId
=
readFileSync
(
buildIdFile
,
'utf8'
).
trim
()
const
buildId
=
readFileSync
(
buildIdFile
,
'utf8'
).
trim
()
...
...
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