Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nordcloud/serverless-jest-plugin
Plugin for Serverless Framework which adds support for test-driven development using Jest
https://github.com/nordcloud/serverless-jest-plugin
mocha serverless-framework serverless-plugin test-driven-development
Last synced: 4 days ago
JSON representation
Plugin for Serverless Framework which adds support for test-driven development using Jest
- Host: GitHub
- URL: https://github.com/nordcloud/serverless-jest-plugin
- Owner: nordcloud
- License: mit
- Created: 2017-01-21T17:33:39.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-05-25T08:36:58.000Z (8 months ago)
- Last Synced: 2025-01-11T10:15:54.748Z (11 days ago)
- Topics: mocha, serverless-framework, serverless-plugin, test-driven-development
- Language: JavaScript
- Homepage:
- Size: 616 KB
- Stars: 120
- Watchers: 17
- Forks: 51
- Open Issues: 24
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Serverless Jest Plugin
[![Build Status](https://travis-ci.org/nordcloud/serverless-jest-plugin.svg?branch=master)](https://travis-ci.org/nordcloud/serverless-jest-plugin)
A Serverless Plugin for the [Serverless Framework](http://www.serverless.com) which
adds support for test-driven development using [jest](https://facebook.github.io/jest/)**THIS PLUGIN REQUIRES SERVERLESS V1.0 OR LATER!**
More familiar with Mocha? Try [serverless-mocha-plugin](https://github.com/nordcloud/serverless-mocha-plugin).
## Introduction
This plugins does the following:
* It provides commands to create and run tests manually
* It provides a command to create a function, which automatically also creates a test## Installation
In your service root, run:
```bash
npm install --save-dev serverless-jest-plugin
```Add the plugin to `serverless.yml`:
```yml
plugins:
- serverless-jest-plugin
custom:
jest:
# You can pass jest options here
# See details here: https://facebook.github.io/jest/docs/configuration.html
# For instance, uncomment next line to enable code coverage
# collectCoverage: true
```## Usage
### Creating functions
Functions (and associated tests) can be created using the command
```
sls create function -f functionName --handler handler
```
e.g.```
sls create function -f myFunction --handler functions/myFunction/index.handler
```creates a new function `myFunction` into `serverless.yml` with a code template for
the handler in `functions/myFunction/index.js` and a Javascript function `module.exports.handler`
as the entrypoint for the Lambda function. A test template is also created into `test/myFunction.js`. Optionally tests can be created to specific folder using `--path` or `-p` switch, e.g.```
sls create function -f myFunction --handler functions/myFunction/index.handler --path tests
```To create tests next to handler use `--path {function}`, in following example test file `myFunction.test.js` is created to `functions/myFunction/` directory.
```
sls create function -f myFunction --handler functions/myFunction/index.handler --path {function}
```### Creating tests
Tests can also be added to existing handlers using
```
sls create test -f functionName
```### Running tests
Tests can be run directly using Jest or using the "invoke test" command
```
sls invoke test [--stage stage] [--region region] [-f function]
```If no function names are passed to "invoke test", all tests related to handler functions are run.
## License
https://github.com/nordcloud/serverless-jest-plugin/blob/master/LICENSE