#Serverless Test Plugin
Simple Integration Test Framework for Serverless. This plugin is basically a
reimplementation of the run
command, validating a function's success. You can test all
functions of your component by passing the --all
option, and write the results into a
JUnit compatible reports XML by specifying --out <file-name>
.
This plugin is intended to run besides your regular Unit Tests such as Mocha, not as a replacement. It will solely validate that your functions have no compilation errors and can successfully run the provided event.json
. At this point there's no output validation other than checking for success, failure or a timeout (that is, if your Lambda code exceeds the specified timeout value).
Typically you want to run this plugin right before deploying your Lambda code.
The easiest example of running this plugin is
serverless function test --all
Note: Serverless v0.1.4 or higher is required.
###Configuration
This plugin can be configured on a function level by adding a test
definition to the custom
section in your s-function.json
.
Example:
"custom": {
"test": {
"skip": true
}
}
Available options are
skip
- boolean; skip this function from all testsevent
- string; name of the event JSON definition; defaults to event.json
###Usage
Test an individual function:
serverless function test <component>/<module>/<function>
Test all functions in the project:
serverless function test --all
Test all functions and output results into a JUnit compatible XML:
serverless function test --all --out test_results/report.xml
To detect whether your code runs in a test environment or not, check for the SERVERLESS_TEST
environment variable:
if (process.env.SERVERLESS_TEST) {
console.log("This code runs as part of an intergration test.");
}