From 123da4f6026c597871e1459ae37956e14ef1c994 Mon Sep 17 00:00:00 2001 From: Nicolas Froidure Date: Tue, 22 Oct 2024 15:12:06 +0200 Subject: [PATCH] fix(@whook/aws-lambda): fix lambdas testing command --- .../src/commands/testConsumerLambda.ts | 21 ++------------ .../src/commands/testCronLambda.ts | 28 ++++--------------- .../src/commands/testHTTPLambda.ts | 24 +++------------- .../src/commands/testKafkaConsumerLambda.ts | 21 ++------------ .../src/commands/testLogSubscriberLambda.ts | 21 ++------------ .../src/commands/testS3Lambda.ts | 21 ++------------ .../src/commands/testTransformerLambda.ts | 21 ++------------ 7 files changed, 25 insertions(+), 132 deletions(-) diff --git a/packages/whook-aws-lambda/src/commands/testConsumerLambda.ts b/packages/whook-aws-lambda/src/commands/testConsumerLambda.ts index 9529d2d2..4de6c6ab 100644 --- a/packages/whook-aws-lambda/src/commands/testConsumerLambda.ts +++ b/packages/whook-aws-lambda/src/commands/testConsumerLambda.ts @@ -69,25 +69,10 @@ async function initTestConsumerLambdaCommand({ extension, ); const parsedEvent = JSON.parse(event); - const result = await new Promise((resolve, reject) => { - const handlerPromise = handler( - parsedEvent, - { - succeed: (...args: unknown[]) => { - handlerPromise.then(resolve.bind(null, ...args)); - }, - fail: reject, - }, - (err: Error, ...args: unknown[]) => { - if (err) { - reject(err); - return; - } - handlerPromise.then(resolve.bind(null, ...args)); - }, - ).catch(reject); - }); + const result = await handler(parsedEvent, {}); log('info', 'SUCCESS:', result as string); + + process.emit('SIGTERM'); }; } diff --git a/packages/whook-aws-lambda/src/commands/testCronLambda.ts b/packages/whook-aws-lambda/src/commands/testCronLambda.ts index eac146ff..78bd5618 100644 --- a/packages/whook-aws-lambda/src/commands/testCronLambda.ts +++ b/packages/whook-aws-lambda/src/commands/testCronLambda.ts @@ -81,29 +81,13 @@ async function initTestCronLambdaCommand({ type, extension, ); - - const result = await new Promise((resolve, reject) => { - const handlerPromise = handler( - { - time: date === 'now' ? new Date(time()).toISOString() : date, - body: JSON.parse(body), - }, - { - succeed: (...args: unknown[]) => { - handlerPromise.then(resolve.bind(null, ...args)); - }, - fail: reject, - }, - (err: Error, ...args: unknown[]) => { - if (err) { - reject(err); - return; - } - handlerPromise.then(resolve.bind(null, ...args)); - }, - ).catch(reject); - }); + const result = await handler({ + time: date === 'now' ? new Date(time()).toISOString() : date, + body: JSON.parse(body), + }, {}); log('info', 'SUCCESS:', result as string); + + process.emit('SIGTERM'); }; } diff --git a/packages/whook-aws-lambda/src/commands/testHTTPLambda.ts b/packages/whook-aws-lambda/src/commands/testHTTPLambda.ts index 01248b35..48c3bd04 100644 --- a/packages/whook-aws-lambda/src/commands/testHTTPLambda.ts +++ b/packages/whook-aws-lambda/src/commands/testHTTPLambda.ts @@ -166,26 +166,10 @@ async function initTestHTTPLambdaCommand({ } log('info', 'AWS_REQUEST:', awsRequest as unknown as string); - const result: APIGatewayProxyResult = await new Promise( - (resolve, reject) => { - const handlerPromise = handler( - awsRequest, - { - succeed: (...args: any[]) => { - handlerPromise.then(resolve.bind(null, ...args)); - }, - fail: reject, - }, - (err: Error, ...args: any[]) => { - if (err) { - reject(err); - return; - } - handlerPromise.then(resolve.bind(null, ...args)); - }, - ).catch(reject); - }, - ); + const result: APIGatewayProxyResult = await handler(awsRequest); + log('info', 'SUCCESS:', result as unknown as string); + + process.emit('SIGTERM'); }; } diff --git a/packages/whook-aws-lambda/src/commands/testKafkaConsumerLambda.ts b/packages/whook-aws-lambda/src/commands/testKafkaConsumerLambda.ts index 4f59d72d..4761d532 100644 --- a/packages/whook-aws-lambda/src/commands/testKafkaConsumerLambda.ts +++ b/packages/whook-aws-lambda/src/commands/testKafkaConsumerLambda.ts @@ -107,25 +107,10 @@ async function initTestKafkaConsumerLambdaCommand({ extension, ); const parsedEvent = JSON.parse(event); - const result = await new Promise((resolve, reject) => { - const handlerPromise = handler( - parsedEvent, - { - succeed: (...args: unknown[]) => { - handlerPromise.then(resolve.bind(null, ...args)); - }, - fail: reject, - }, - (err: Error, ...args: unknown[]) => { - if (err) { - reject(err); - return; - } - handlerPromise.then(resolve.bind(null, ...args)); - }, - ).catch(reject); - }); + const result = await handler(parsedEvent, {}); log('info', 'SUCCESS:', result as string); + + process.emit('SIGTERM'); }; } diff --git a/packages/whook-aws-lambda/src/commands/testLogSubscriberLambda.ts b/packages/whook-aws-lambda/src/commands/testLogSubscriberLambda.ts index e43b40b9..344068d8 100644 --- a/packages/whook-aws-lambda/src/commands/testLogSubscriberLambda.ts +++ b/packages/whook-aws-lambda/src/commands/testLogSubscriberLambda.ts @@ -97,25 +97,10 @@ async function initTestS3LambdaCommand({ data: await encodePayload(JSON.parse(event)), }, }; - const result = await new Promise((resolve, reject) => { - const handlerPromise = handler( - parsedEvent, - { - succeed: (...args: unknown[]) => { - handlerPromise.then(resolve.bind(null, ...args)); - }, - fail: reject, - }, - (err: Error, ...args: unknown[]) => { - if (err) { - reject(err); - return; - } - handlerPromise.then(resolve.bind(null, ...args)); - }, - ).catch(reject); - }); + const result = await handler(parsedEvent, {}); log('info', 'SUCCESS:', result as string); + + process.emit('SIGTERM'); }; } diff --git a/packages/whook-aws-lambda/src/commands/testS3Lambda.ts b/packages/whook-aws-lambda/src/commands/testS3Lambda.ts index a4b73188..0d59ec3d 100644 --- a/packages/whook-aws-lambda/src/commands/testS3Lambda.ts +++ b/packages/whook-aws-lambda/src/commands/testS3Lambda.ts @@ -109,25 +109,10 @@ async function initTestS3LambdaCommand({ extension, ); const parsedEvent = JSON.parse(event); - const result = await new Promise((resolve, reject) => { - const handlerPromise = handler( - parsedEvent, - { - succeed: (...args: unknown[]) => { - handlerPromise.then(resolve.bind(null, ...args)); - }, - fail: reject, - }, - (err: Error, ...args: unknown[]) => { - if (err) { - reject(err); - return; - } - handlerPromise.then(resolve.bind(null, ...args)); - }, - ).catch(reject); - }); + const result = await handler(parsedEvent, {}); log('info', 'SUCCESS:', result as string); + + process.emit('SIGTERM'); }; } diff --git a/packages/whook-aws-lambda/src/commands/testTransformerLambda.ts b/packages/whook-aws-lambda/src/commands/testTransformerLambda.ts index 926d7f00..c1cb3ddf 100644 --- a/packages/whook-aws-lambda/src/commands/testTransformerLambda.ts +++ b/packages/whook-aws-lambda/src/commands/testTransformerLambda.ts @@ -80,25 +80,10 @@ async function initTestTransformerLambdaCommand({ extension, ); const parsedEvent = JSON.parse(event); - const result = await new Promise((resolve, reject) => { - const handlerPromise = handler( - parsedEvent, - { - succeed: (...args: unknown[]) => { - handlerPromise.then(resolve.bind(null, ...args)); - }, - fail: reject, - }, - (err: Error, ...args: unknown[]) => { - if (err) { - reject(err); - return; - } - handlerPromise.then(resolve.bind(null, ...args)); - }, - ).catch(reject); - }); + const result = await handler(parsedEvent, {}); log('info', 'SUCCESS:', result as string); + + process.emit('SIGTERM'); }; }