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
Serverless plugin test helper
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:
- 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) - 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:
- Install project and dependencies
- Run unit tests
- Deploy to a static environment (using
--stage <environment>
option in Serverless Framework) - Run e2e tests on the environment ... repeat for all static, non-prod environments ... include a manual step if want to gate production deploys
- Deploy to production environment (using
--stage production
) - Run e2e tests in production
For checkins/merges to a feature branch:
- Install project and dependencies
- Run unit tests
- Deploy to a dynamic environment (using
--stage <branch or username>
option in Serverless Framework) - 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?