0.5.1 • Published 9 months ago

simple-lambda-testing-methods v0.5.1

Weekly downloads
2
License
-
Repository
github
Last release
9 months ago

simple-lambda-testing-methods

a simple library made to make it easy to test lambdas and handlers, deployed and locally.

installation

npm install --save simple-lambda-testing-methods

usage

invokeHandlerForTesting

When you have a handler that uses the callback pattern (e.g., middy based handlers), you can use this method to interact with it using async/await instead.

This is useful for unit tests and integration tests.

import { invokeHandlerForTesting } from 'simple-lambda-testing-methods';
import { handler } from `src/handlers/sendUserNotification.ts`;

const response = await invokeHandlerForTesting({
  handler,
  event: { important: 'data' },
});

invokeLambdaForTesting

When you'd like to actually invoke your live, deployed lambda, for an acceptance test for example, this function will let you do so with a convenient api. It uses simple-lambda-client under the hood, so that you'll see the same response exact any clients of this lambda would see.

import { invokeLambdaForTesting } from 'simple-lambda-testing-methods';

const response = await invokeLambdaForTesting({
  service: 'svc-notifications',
  function: 'sendUserNotification',
  stage: 'prod',
  event: { important: 'data' },
});

If you're using the serverless framework (i.e., you have a serverless.yml file in your project's root), then this method can also allow you to invoke your lambda locally when setting the locally flag.

import { invokeLambdaForTesting } from 'simple-lambda-testing-methods';

const response = await invokeLambdaForTesting({
  service: 'svc-notifications',
  function: 'sendUserNotification',
  stage: 'prod',
  locally: true,
  event: { important: 'data' },
});

When running with the locally flag, this method will simply lookup your function's file path from the serverless.yml, import the function, and invoke it using the invokeHandlerForTesting method. Its a nice sanity check that helps debug differences in the same exact test between your deployed code and the same code locally.

0.5.0

9 months ago

0.5.1

9 months ago

0.4.2

1 year ago

0.2.1

2 years ago

0.2.0

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.1

2 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

4 years ago