Skip to content

Commit

Permalink
close #93
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydaly committed Feb 6, 2019
1 parent 2e55d2f commit 0964958
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export declare interface App {
export declare type Middleware = (req: Request, res: Response, next: Middleware) => void;
export declare type ErrorHandlingMiddleware = (error: Error, req: Request, res: Response, next: ErrorHandlingMiddleware) => void;
export declare type ErrorCallback = (error?: Error) => void;
export declare type HandlerFunction = (req: Request, res: Response, next?: NextFunction) => void | {} | Promise<{}>;
export declare type HandlerFunction = (req?: Request, res?: Response, next?: NextFunction) => void | {} | Promise<{}>;
export declare type LoggerFunction = (message: string) => void;
export declare type NextFunction = () => void;
export declare type TimestampFunction = () => string;
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class API {

// Extract the execution stack
let stack = args.map((fn,i) => {
if (typeof fn === 'function' && (fn.length === 3 || (fn.length === 2 && i === args.length-1)))
if (typeof fn === 'function' && (fn.length === 3 || (i === args.length-1)))
return fn
throw new ConfigurationError('Route-based middleware must have 3 parameters')
})
Expand Down
22 changes: 19 additions & 3 deletions test/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ api.get('/', function(req,res) {
res.status(200).json({ method: 'get', status: 'ok' })
})


api.get('/return', async function(req,res) {
return { method: 'get', status: 'ok' }
})

api.get('/returnNoArgs', async () => {
return { method: 'get', status: 'ok' }
})

api2.get('/', function(req,res) {
res.status(200).json({ method: 'get', status: 'ok' })
})
Expand Down Expand Up @@ -310,6 +315,18 @@ describe('Route Tests:', function() {
}) // end it


it('Simple path w/ async return (no args)', async function() {
let _event = Object.assign({},event,{ path: '/returnNoArgs' })
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
expect(result).to.deep.equal({
multiValueHeaders: { 'content-type': ['application/json'] },
statusCode: 200,
body: '{"method":"get","status":"ok"}',
isBase64Encoded: false
})
}) // end it


it('Simple path, no `context`', async function() {
let _event = Object.assign({},event,{})
let result = await new Promise(r => api.run(_event,null,(e,res) => { r(res) }))
Expand Down Expand Up @@ -1029,7 +1046,7 @@ describe('Route Tests:', function() {

describe('Configuration errors', function() {

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

// TODO: ???
it('Missing callback', async function() {
it('Missing handler', async function() {
let error
try {
const api_error1 = require('../index')({ version: 'v1.0' })
Expand Down

0 comments on commit 0964958

Please sign in to comment.