From 0929906e6e5785af1926ba8162a60c4973ea789a Mon Sep 17 00:00:00 2001 From: abetomo Date: Tue, 27 Jun 2017 15:25:57 +0900 Subject: [PATCH] Add simple context method --- lib/main.js | 10 ++++++++++ test/main.js | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/main.js b/lib/main.js index 3204c7e0..35bbe474 100644 --- a/lib/main.js +++ b/lib/main.js @@ -97,6 +97,16 @@ Lambda.prototype._runHandler = (handler, event, program, context) => { return timeout - (currentTime - startTime) } + // The following three functions are deprecated in AWS Lambda. + // Since it is sometimes used by other SDK, + // it is a simple one that does not result in `not function` error + context.succeed = (result) => console.log(JSON.stringify(result)) + context.fail = (error) => console.log(JSON.stringify(error)) + context.done = (error, results) => { + console.log(JSON.stringify(error)) + console.log(JSON.stringify(results)) + } + handler(event, context, callback) } diff --git a/test/main.js b/test/main.js index ad09bd18..ad42cc19 100644 --- a/test/main.js +++ b/test/main.js @@ -135,6 +135,18 @@ describe('lib/main', function () { }) }) + describe('_runHandler', () => { + it('context methods is a function', (done) => { + const handler = (event, context, callback) => { + assert.isFunction(context.succeed) + assert.isFunction(context.fail) + assert.isFunction(context.done) + done() + } + lambda._runHandler(handler, {}, program, {}) + }) + }) + describe('_params', function () { // http://docs.aws.amazon.com/lambda/latest/dg/API_CreateFunction.html#SSS-CreateFunction-request-FunctionName const functionNamePattern =