Skip to content

Commit

Permalink
Correctly mirror lambda's null-return behaviour (#220)
Browse files Browse the repository at this point in the history
* add acceptance test

* fix: replicate lambda behaviour where returning synchronously is ignored
  • Loading branch information
Skn0tt committed Feb 15, 2022
1 parent fb0aece commit 8e5afac
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lambdalocal.ts
Expand Up @@ -252,7 +252,7 @@ function _executeSync(opts) {
if (result.then) {
result.then(ctx.succeed, ctx.fail);
} else {
ctx.succeed(result);
ctx.succeed(null);
}
}
} catch(err){
Expand Down
13 changes: 13 additions & 0 deletions test/functs/test-func-synchronous.js
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2018. Taimos GmbH http://www.taimos.de
*/

/*
* Lambda function used for basic test.
*/
exports.handler = function (event, context) {
return {
statusCode: 200,
body: "this response won't go anywhere!",
};
};
16 changes: 16 additions & 0 deletions test/test.js
Expand Up @@ -324,6 +324,22 @@ describe("- Testing lambdalocal.js", function () {
});
});
});
describe('* Synchronous return', function () {
it('should return null', function () {
var lambdalocal = require(lambdalocal_path);
lambdalocal.setLogger(winston);
return lambdalocal.execute({
event: require(path.join(__dirname, "./events/test-event.js")),
lambdaPath: path.join(__dirname, "./functs/test-func-synchronous.js"),
lambdaHandler: functionName,
callbackWaitsForEmptyEventLoop: false,
timeoutMs: timeoutMs,
verboseLevel: 1
}).then(data => {
assert.isNull(data)
})
});
});
if (get_node_major_version() >= 2) {
describe('* Promised Run', function () {
var opts = {
Expand Down

0 comments on commit 8e5afac

Please sign in to comment.