JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 22057
  • Score
    100M100P100Q137488F
  • License BSD-3-Clause

Unit/Integration tests for AWS Lambda handlers

Package Exports

  • lambda-tester

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (lambda-tester) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Build Status npm version

lambda-tester

Simplifies writing unit tests for AWS Lambda functions using Node.js.

Features

  • Verifies correct handler behavior
  • Works asynchronously
  • Verifies Node.js runtime version
  • AWS X-Ray support [experimental]
  • Detects resource leaks [experimental]
  • Supports Promises
  • Easily integrates with test frameworks (Mocha and Jasmine)
  • Handlers can be loaded and removed after execution
  • Lightweight and won't impact performance
  • Maps the environment variable LAMBDA_TASK_ROOT to the application's root
  • Automatically loads .env files
  • Works with Node 6.10.x

Installation

Install via npm.

npm install lambda-tester --save-dev

Getting Started

Lambda handlers with support for callbacks use the typical Node.js asynchronous signature:

exports.handler = function( event, context, callback ) {

    callback( null, 'success!' );
}

The following example shows a simple case for validating that the Lambda (handler) was called successfully (i.e. callback( null, result ):

const LambdaTester = require( 'lambda-tester' );

const myHandler = require( '../index' ).handler;

describe( 'handler', function() {

    it( 'test success', function() {

        return LambdaTester( myHandler )
            .event( { name: 'Fred' } )
            .expectResult();
    });
});

If the handler decides to call callback( err ) then the verification will fail and the test will fail.

Additionally, if one wanted to test for failure, then the following code would be used:

const LambdaTester = require( 'lambda-tester' );

const myHandler = require( '../index' ).handler;

describe( 'handler', function() {

    it( 'test failure', function() {

        return LambdaTester( myHandler )
            .event( { name: 'Unknown' } )
            .expectError();
    });
});

Please note that you must return the LambdaTester back to the framework since lambda-tester is asynchronous and uses Promises.

Documentation

Complete documentation can be found in our documentation page.

Projects Using lambda-tester

  • vandium - Secures and simplifies AWS Lambda handlers

Feedback

We'd love to get feedback on how you're using lambda-tester and things we could add to make this tool better. Feel free to contact us at feedback@vandium.io

Compatibility

Version 3.x targets Lambda handlers using Node 6.10.x. If you require support for Node 4.x, please use version 2.x

License

BSD-3-Clause