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
7cca2b0d
Unverified
Commit
7cca2b0d
authored
May 11, 2020
by
Tim Neutkens
Committed by
GitHub
May 11, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test for API route with fetch polyfill (#12680)
parent
29b11000
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
1 deletion
+22
-1
api-route.js
test/integration/fetch-polyfill/pages/api/api-route.js
+6
-0
serverless-server.js
test/integration/fetch-polyfill/serverless-server.js
+7
-0
index.test.js
test/integration/fetch-polyfill/test/index.test.js
+9
-1
No files found.
test/integration/fetch-polyfill/pages/api/api-route.js
0 → 100644
View file @
7cca2b0d
export
default
async
function
ApiRoute
(
_req
,
res
)
{
const
port
=
process
.
env
.
NEXT_PUBLIC_API_PORT
const
response
=
await
fetch
(
`http://localhost:
${
port
}
/`
)
const
json
=
await
response
.
json
()
res
.
json
(
json
)
}
test/integration/fetch-polyfill/serverless-server.js
View file @
7cca2b0d
...
...
@@ -14,6 +14,13 @@ const server = http.createServer((req, res) => {
)
}
if
(
req
.
url
===
'/api/api-route'
)
{
return
require
(
'./.next/serverless/pages/api/api-route.js'
).
default
(
req
,
res
)
}
if
(
req
.
url
===
'/static'
)
{
return
send
(
req
,
...
...
test/integration/fetch-polyfill/test/index.test.js
View file @
7cca2b0d
...
...
@@ -7,6 +7,7 @@ import {
findPort
,
launchApp
,
initNextServerScript
,
fetchViaHTTP
,
renderViaHTTP
,
nextBuild
,
nextStart
,
...
...
@@ -72,9 +73,16 @@ function runTests() {
const
html
=
await
renderViaHTTP
(
appPort
,
'/getinitialprops'
)
expect
(
html
).
toMatch
(
/bar/
)
})
it
(
'includes polyfilled fetch when using API routes'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
appPort
,
'/api/api-route'
)
const
json
=
await
res
.
json
()
expect
(
json
.
foo
).
toBe
(
'bar'
)
})
}
describe
(
'
API routes
'
,
()
=>
{
describe
(
'
Fetch polyfill
'
,
()
=>
{
describe
(
'dev support'
,
()
=>
{
beforeAll
(
async
()
=>
{
appPort
=
await
findPort
()
...
...
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