5.2.0 • Published 4 months ago

@lifeomic/test-tool-lambda v5.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

@lifeomic/test-tool-lambda

npm Build Status

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();
5.2.0

4 months ago

5.1.1

4 months ago

5.1.0

8 months ago

5.0.0

8 months ago