Unverified Commit 7cca2b0d authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Add test for API route with fetch polyfill (#12680)

parent 29b11000
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)
}
......@@ -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,
......
......@@ -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()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment