Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
12 changes: 12 additions & 0 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down