@lifeomic/test-tool-lambda
v5.2.1
Published
[![npm](https://img.shields.io/npm/v/@lifeomic/test-tool-lambda.svg)](https://www.npmjs.com/package/@lifeomic/test-tool-lambda) [![Build Status](https://github.com/lifeomic/test-tools/actions/workflows/release.yaml/badge.svg)](https://github.com/lifeomic/
Downloads
16
Readme
@lifeomic/test-tool-lambda
Lambda convenience methods
Create
createFunction
takes care of some of the configuration settings for localstack.
import { createFunction } from '@lifeomic/test-tool-lambda';
// Just an example, make sure you are pointing to the correct zip file.
const zipFilePath = path.join(__dirname, '../../../deploy/terraform/build/myFunctionFile.zip');
await createFunction({
FunctionName: 'myFunction',
Runtime: 'nodejs18.x',
MemorySize: 1024,
Timeout: 10,
Handler: 'myFunctionFile.handlerFunctionName',
zipFilePath,
env: {
LAMBDA_ENDPOINT: 'http://mockserver:1080/lambda',
}
});
Test Hooks
lambdaHooks
provides some convenience around test before/after stuff. It can be used in a global/file/test centric way.
The uniqueNames
boolean causes the lib to create unique functions for every before
call. This can be useful if you
want unique lambdas per test/file.
import { lambdaHooks } from '@lifeomic/test-tool-lambda';
// Just an example, make sure you are pointing to the correct zip file.
const zipFilePath = path.join(__dirname, '../../../deploy/terraform/build/myFunctionFile.zip');
const hooks = lambdaHooks({
uniqueNames: true,
lambdas: [{
functionName: 'myFunction',
Runtime: 'nodejs18.x',
MemorySize: 1024,
Timeout: 10,
Handler: 'myFunctionFile.handlerFunctionName',
zipFilePath,
env: {
LAMBDA_ENDPOINT: 'http://mockserver:1080/lambda',
}
}],
});
// Calls out to AWS api until ListFunctionsCommand returns successfully
await hooks.beforeAll();
// Creates the lambdas defined above, and returns an object with `[functionName]: possiblyUniqueFunctionName`
const context = await hooks.before();
const functionName = context.functionName;
// Calls Lambda.deleteFunction
await hooks.after();
// Destroys the client, closing any open sockets.
await hooks.afterAll();