Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

serverless-test-plugin

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

serverless-test-plugin

Serverless Test Plugin - Integration Tests for the Serverless Framework.

  • 0.2.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
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.5.0 or higher is required.

Usage

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

Run Tests

Test an individual function:

serverless function test <function>

To test all functions in the current path, invoke the plugin without any function name:

serverless function test

To test all functions in the project specify the --all parameter:

serverless function test --all

You can also specify a stage and/or a region for your tests. If none is specified, the first stage and region defined in your _meta folder will be used:

serverless function test <function> --stage dev --region us-east-1

To test all functions and output results into a JUnit compatible XML, specify the --out parameter with a target file name:

serverless function test --all --out test_results/report.xml

Sometimes it is desirable to mock certain behavior in your code depending on whether it is running in a test automation script or on an actual server. For this reason the serverless-test-plugin introduces a dedicated environment variable SERVERLESS_TEST:

if (process.env.SERVERLESS_TEST) {
  console.log("This code runs as part of an integration test.");
}
else {
  console.log("This code does NOT run as part of an integration test..")
}

Releases

0.2.4

  • New command line option --dont-fail-on-error which makes the plugin exit with error code 0 even in case a test fails. This enables the same behavior as before the 0.2.2 update.

0.2.3

  • Properly time out a function call, e.g. in case the response callback is never invoked.

0.2.2

  • Exit with error code 1 in case one or more tests fail. This should help integrating the plugin in your automation/CI/CD workflows.

0.2.1

  • Fixed an issue with the plugin not reporting error responses correctly.

0.2.0

  • Support for Serverless 0.5.0 and higher.

0.1.5

  • Fixed broken build. Sorry for that.

0.1.4

  • Set an environment variable SERVERLESS_TEST the invoked functions can check for

0.1.3

  • Cleanups

0.1.2

  • Cleanups

0.1.1

  • Capture stdout and stderr output of tests

0.1.0

  • Initial Release.

Keywords

FAQs

Package last updated on 28 Jun 2016

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc