Skip to content

Commit

Permalink
fix(@whook/aws-lambda): fix lambdas testing command
Browse files Browse the repository at this point in the history
  • Loading branch information
nfroidure committed Oct 22, 2024
1 parent 7c62c83 commit 123da4f
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 132 deletions.
21 changes: 3 additions & 18 deletions packages/whook-aws-lambda/src/commands/testConsumerLambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
};
}
28 changes: 6 additions & 22 deletions packages/whook-aws-lambda/src/commands/testCronLambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
};
}
24 changes: 4 additions & 20 deletions packages/whook-aws-lambda/src/commands/testHTTPLambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
};
}
21 changes: 3 additions & 18 deletions packages/whook-aws-lambda/src/commands/testKafkaConsumerLambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
};
}
21 changes: 3 additions & 18 deletions packages/whook-aws-lambda/src/commands/testLogSubscriberLambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
};
}
21 changes: 3 additions & 18 deletions packages/whook-aws-lambda/src/commands/testS3Lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
};
}
21 changes: 3 additions & 18 deletions packages/whook-aws-lambda/src/commands/testTransformerLambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
};
}

0 comments on commit 123da4f

Please sign in to comment.