@smallwins/lambda
Advanced tools
Comparing version 1.1.2 to 2.0.0
18
index.js
@@ -5,4 +5,2 @@ var async = require('async') | ||
var firstRun = true | ||
/** | ||
@@ -14,4 +12,4 @@ * lambda - accepts node style callbacks and returns an aws lambda function | ||
// grab all the functions | ||
var fns = [].slice.call(arguments, 0) | ||
var firstRun = true // important to keep this here in this closure | ||
var fns = [].slice.call(arguments, 0) // grab all the functions | ||
@@ -32,4 +30,4 @@ // fail loudly for programmer not passing anything | ||
if(firstRun) { | ||
// put this callback at the front of the line to pass in the event data | ||
// this is to avoid warm start (sometimes lambda containers are cached … yeaaaaah.) | ||
if (firstRun) { | ||
fns.unshift(function(callback) { | ||
@@ -40,2 +38,10 @@ callback(null, event) | ||
} | ||
else { | ||
// mutates! wtf. remove the cached callback | ||
fns.shift() | ||
// add the fresh event | ||
fns.unshift(function(callback) { | ||
callback(null, event) | ||
}) | ||
} | ||
@@ -42,0 +48,0 @@ // the real worker here |
{ | ||
"name": "@smallwins/lambda", | ||
"version": "1.1.2", | ||
"version": "2.0.0", | ||
"description": "Author your AWS Lambda functions as node style errbacks.", | ||
@@ -5,0 +5,0 @@ "main": "index", |
@@ -43,40 +43,1 @@ var test = require('tape') | ||
}) | ||
test('can invoke a successful lambda', t=> { | ||
t.plan(1) | ||
// always succeeds | ||
function tester(event, callback) { | ||
event.allGood = true | ||
callback(null, event) | ||
} | ||
// mocks don't need a cray mocking lib | ||
var fakeEvent = {} | ||
var fakeContext = { | ||
succeed: function fakeSucceed(v) { | ||
t.ok(v.allGood, 'got the event!') | ||
console.log('fake succeed called with ', v) | ||
} | ||
} | ||
// get our lambda and invoke it with the mocks | ||
var fn = lambda(tester) | ||
fn(fakeEvent, fakeContext) | ||
}) | ||
test('can invoke a failful lambda', t=> { | ||
t.plan(1) | ||
// always succeeds | ||
function tester(callback) { | ||
callback(Error('wtf')) | ||
} | ||
// mocks don't need a cray mocking lib | ||
var fakeEvent = {} | ||
var fakeContext = { | ||
succeed: function fakeSucceed(v) { | ||
t.ok(isArray(v), 'got an Errors array') | ||
console.log('faked fail called with ', v) | ||
} | ||
} | ||
// get our lambda and invoke it with the mocks | ||
var fn = lambda(tester) | ||
fn(fakeEvent, fakeContext) | ||
}) |
8827
8
143