Skip to content

Commit 0964958

Browse files
committed
close #93
1 parent 2e55d2f commit 0964958

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export declare interface App {
3939
export declare type Middleware = (req: Request, res: Response, next: Middleware) => void;
4040
export declare type ErrorHandlingMiddleware = (error: Error, req: Request, res: Response, next: ErrorHandlingMiddleware) => void;
4141
export declare type ErrorCallback = (error?: Error) => void;
42-
export declare type HandlerFunction = (req: Request, res: Response, next?: NextFunction) => void | {} | Promise<{}>;
42+
export declare type HandlerFunction = (req?: Request, res?: Response, next?: NextFunction) => void | {} | Promise<{}>;
4343
export declare type LoggerFunction = (message: string) => void;
4444
export declare type NextFunction = () => void;
4545
export declare type TimestampFunction = () => string;

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class API {
8888

8989
// Extract the execution stack
9090
let stack = args.map((fn,i) => {
91-
if (typeof fn === 'function' && (fn.length === 3 || (fn.length === 2 && i === args.length-1)))
91+
if (typeof fn === 'function' && (fn.length === 3 || (i === args.length-1)))
9292
return fn
9393
throw new ConfigurationError('Route-based middleware must have 3 parameters')
9494
})

test/routes.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,15 @@ api.get('/', function(req,res) {
2828
res.status(200).json({ method: 'get', status: 'ok' })
2929
})
3030

31+
3132
api.get('/return', async function(req,res) {
3233
return { method: 'get', status: 'ok' }
3334
})
3435

36+
api.get('/returnNoArgs', async () => {
37+
return { method: 'get', status: 'ok' }
38+
})
39+
3540
api2.get('/', function(req,res) {
3641
res.status(200).json({ method: 'get', status: 'ok' })
3742
})
@@ -310,6 +315,18 @@ describe('Route Tests:', function() {
310315
}) // end it
311316

312317

318+
it('Simple path w/ async return (no args)', async function() {
319+
let _event = Object.assign({},event,{ path: '/returnNoArgs' })
320+
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
321+
expect(result).to.deep.equal({
322+
multiValueHeaders: { 'content-type': ['application/json'] },
323+
statusCode: 200,
324+
body: '{"method":"get","status":"ok"}',
325+
isBase64Encoded: false
326+
})
327+
}) // end it
328+
329+
313330
it('Simple path, no `context`', async function() {
314331
let _event = Object.assign({},event,{})
315332
let result = await new Promise(r => api.run(_event,null,(e,res) => { r(res) }))
@@ -1029,7 +1046,7 @@ describe('Route Tests:', function() {
10291046

10301047
describe('Configuration errors', function() {
10311048

1032-
it('Missing handler', async function() {
1049+
it('Missing handler (w/ route)', async function() {
10331050
let error
10341051
try {
10351052
const api_error1 = require('../index')({ version: 'v1.0' })
@@ -1042,8 +1059,7 @@ describe('Route Tests:', function() {
10421059
expect(error.message).to.equal('No handler or middleware specified for GET method on /test-missing-handler route.')
10431060
}) // end it
10441061

1045-
// TODO: ???
1046-
it('Missing callback', async function() {
1062+
it('Missing handler', async function() {
10471063
let error
10481064
try {
10491065
const api_error1 = require('../index')({ version: 'v1.0' })

0 commit comments

Comments
 (0)