Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
return a proper error if middleware or api/route return not a
falsy or Response value.
- Loading branch information
Showing
6 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// populated with tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// populated with tests | ||
export default () => { | ||
return 'Boom' | ||
} | ||
|
||
export const config = { matcher: '/' } |
5 changes: 5 additions & 0 deletions
5
test/integration/edge-runtime-response-error/pages/api/route.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default async function handler(request) { | ||
return 'Boom' | ||
} | ||
|
||
export const config = { runtime: 'experimental-edge' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Page() { | ||
return <div>ok</div> | ||
} |
88 changes: 88 additions & 0 deletions
88
test/integration/edge-runtime-response-error/test/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* eslint-disable jest/no-identical-title */ | ||
/* eslint-env jest */ | ||
|
||
import { remove } from 'fs-extra' | ||
import { join } from 'path' | ||
import { | ||
fetchViaHTTP, | ||
File, | ||
findPort, | ||
killApp, | ||
launchApp, | ||
nextBuild, | ||
nextStart, | ||
} from 'next-test-utils' | ||
|
||
jest.setTimeout(1000 * 60 * 2) | ||
|
||
const context = { | ||
appDir: join(__dirname, '../'), | ||
logs: { output: '', stdout: '', stderr: '' }, | ||
api: new File(join(__dirname, '../pages/api/route.js')), | ||
lib: new File(join(__dirname, '../lib.js')), | ||
middleware: new File(join(__dirname, '../middleware.js')), | ||
page: new File(join(__dirname, '../pages/index.js')), | ||
} | ||
const appOption = { | ||
env: { __NEXT_TEST_WITH_DEVTOOL: 1 }, | ||
onStdout(msg) { | ||
context.logs.output += msg | ||
context.logs.stdout += msg | ||
}, | ||
onStderr(msg) { | ||
context.logs.output += msg | ||
context.logs.stderr += msg | ||
}, | ||
} | ||
const routeUrl = '/api/route' | ||
const middlewareUrl = '/' | ||
|
||
describe('Edge runtime code with imports', () => { | ||
beforeEach(async () => { | ||
context.appPort = await findPort() | ||
context.logs = { output: '', stdout: '', stderr: '' } | ||
await remove(join(__dirname, '../.next')) | ||
}) | ||
|
||
afterEach(() => { | ||
if (context.app) { | ||
killApp(context.app) | ||
} | ||
context.api.restore() | ||
context.middleware.restore() | ||
context.lib.restore() | ||
context.page.restore() | ||
}) | ||
|
||
describe.each([ | ||
{ | ||
title: 'Edge API', | ||
url: routeUrl, | ||
}, | ||
{ | ||
title: 'Middleware', | ||
url: middlewareUrl, | ||
}, | ||
])('test error if response is not Response type', ({ title, url }) => { | ||
it(`${title} dev test Response`, async () => { | ||
context.app = await launchApp(context.appDir, context.appPort, appOption) | ||
const res = await fetchViaHTTP(context.appPort, url) | ||
expect(context.logs.stderr).toContain( | ||
'Response must be an instance of Response type' | ||
) | ||
expect(res.status).toBe(500) | ||
}) | ||
|
||
it(`${title} build test Response`, async () => { | ||
await nextBuild(context.appDir, undefined, { | ||
stderr: true, | ||
}) | ||
context.app = await nextStart(context.appDir, context.appPort, appOption) | ||
const res = await fetchViaHTTP(context.appPort, url) | ||
expect(context.logs.stderr).toContain( | ||
'Response must be an instance of Response type' | ||
) | ||
expect(res.status).toBe(500) | ||
}) | ||
}) | ||
}) |