diff --git a/src/Context.ts b/src/Context.ts index 301d3694..2e6e2264 100644 --- a/src/Context.ts +++ b/src/Context.ts @@ -37,7 +37,7 @@ export function CreateContextAndInputs(info: FunctionInfo, request: rpc.IInvocat if (httpInput) { context.req = new Request(httpInput); context.res = new Response(context.done); - // This is added for backwards compatability with what the host used to send to the worker + // This is added for backwards compatibility with what the host used to send to the worker context.bindingData.sys = { methodName: info.name, utcNow: (new Date()).toISOString(), diff --git a/src/WorkerChannel.ts b/src/WorkerChannel.ts index 172e4a78..cc3315d8 100644 --- a/src/WorkerChannel.ts +++ b/src/WorkerChannel.ts @@ -227,10 +227,10 @@ export class WorkerChannel implements IWorkerChannel { response.outputData = []; try { - if (result) { + if (result != null) { let returnBinding = info.getReturnBinding(); // Set results from return / context.done - if (result.return) { + if (result.return != null) { if (this._v1WorkerBehavior) { response.returnValue = toTypedData(result.return); } else { diff --git a/test/WorkerChannelTests.ts b/test/WorkerChannelTests.ts index 0cb903ab..3204db7c 100644 --- a/test/WorkerChannelTests.ts +++ b/test/WorkerChannelTests.ts @@ -455,6 +455,45 @@ describe('WorkerChannel', () => { assertInvocationSuccess(expectedOutput, expectedReturnValue); }); + it ('returns and serializes falsy value: ""', () => { + loader.getFunc.returns((context) => context.done(null, "")); + loader.getInfo.returns(new FunctionInfo(orchestratorBinding)); + + sendInvokeMessage([], getHttpTriggerDataMock()); + + const expectedOutput = []; + const expectedReturnValue = { + string: "" + }; + assertInvocationSuccess(expectedOutput, expectedReturnValue); + }); + + it ('returns and serializes falsy value: 0', () => { + loader.getFunc.returns((context) => context.done(null, 0)); + loader.getInfo.returns(new FunctionInfo(orchestratorBinding)); + + sendInvokeMessage([], getHttpTriggerDataMock()); + + const expectedOutput = []; + const expectedReturnValue = { + int: 0 + }; + assertInvocationSuccess(expectedOutput, expectedReturnValue); + }); + + it ('returns and serializes falsy value: false', () => { + loader.getFunc.returns((context) => context.done(null, false)); + loader.getInfo.returns(new FunctionInfo(orchestratorBinding)); + + sendInvokeMessage([], getHttpTriggerDataMock()); + + const expectedOutput = []; + const expectedReturnValue = { + json: "false" + }; + assertInvocationSuccess(expectedOutput, expectedReturnValue) + }); + it ('returned output is ignored if http', () => { loader.getFunc.returns((context) => context.done(null, ["hello, seattle!", "hello, tokyo!"])); loader.getInfo.returns(new FunctionInfo(httpResBinding));