Socket
Socket
Sign inDemoInstall

serverless-test-plugin

Package Overview
Dependencies
25
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    serverless-test-plugin

Serverless Test Plugin - Integration Tests for the Serverless Framework.


Version published
Maintainers
1
Created

Readme

Source

#Serverless Test Plugin

npm version

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 tests
  • event - 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.");
}

Keywords

FAQs

Last updated on 09 Mar 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc