JSPM

  • Created
  • Published
  • Downloads 2719
  • Score
    100M100P100Q120952F
  • License MIT

A utility library to help with testing deployed serverless applications

Package Exports

  • serverless-plugin-test-helper

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 (serverless-plugin-test-helper) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

version downloads coverage license

Build dependabot dependencies dev dependencies

Serverless plugin test helper

  1. Library overview
  2. Installation and setup
  3. An opinionated approach to serverless testing

Library overview

This library helps out with end-to-end testing of applications and services deployed using the Serverless Framework by locally persisting and exposing dynamic AWS resource information such as endpoint URLs.

The library has two parts:

  1. A Serverless Framework plugin which extends sls deploy to save a local copy of the generated CloudFormation Stack output (which includes service information such as endpoint URLs)
  2. A standard Nodejs library which can be imported to access the output values in tests

Installation and setup

Install and save to package.json as a dev dependency:

npm i -D serverless-plugin-test-helper

Register the plugin in serverless.yml plugins section to save the stack output:

plugins:
  - serverless-plugin-test-helper

Import the helper functions into your test files for getting values from the stack output:

import { getDeployedUrl } from 'serverless-plugin-test-helper';
const URL = getDeployedUrl();

An opinionated approach to serverless testing

Due to tight coupling with managed services and the difficulty in mocking those same services locally, end-to-end testing is incredibly important for deploying serverless applications with confidence (citations needed). Given the dynamic nature of cloud service names and arns it can be difficult to setup a fully-automated test suite, increasing the barrier to entry for clean end-to-end tests. A good deployment pipeline setup should include the following steps, in order: TODO: trunk based development, account separation, Odin

For checkins/merges to master branch:

  1. Install project and dependencies
  2. Run unit tests
  3. Deploy to a static environment (using --stage <environment> option in Serverless Framework)
  4. Run e2e tests on the environment ... repeat for all static, non-prod environments ... include a manual step if want to gate production deploys
  5. Deploy to production environment (using --stage production)
  6. Run e2e tests in production

For checkins/merges to a feature branch:

  1. Install project and dependencies
  2. Run unit tests
  3. Deploy to a dynamic environment (using --stage <branch or username> option in Serverless Framework)
  4. Run e2e tests on dynamic environment

This library supports this kind of pipeline testing approach by saving AWS service configurations from CloudFormation Stack output to a local file after the serverless deployment (sls deploy) so that the values can be referenced in later steps for calling those deployed resources. TODO link to circleci config as an example TODO sample hello world project in the repo?