<commit_before># Serverless Mocha Plugin

A Serverless Plugin for the [Serverless Framework](http://www.serverless.com) which
adds support for test driven development using [mocha](https://mochajs.org/)

**THIS PLUGIN REQUIRES SERVERLESS V0.5 OR HIGHER!**

## Introduction

This plugins does the following:

* It will create test files when creating new serverless functions

* It provides commands to create and run tests manually

## Installation

In your project root, run:

```bash
npm install --save serverless-mocha-plugin
```

Add the plugin to `s-project.json`:

```json
"plugins": [
  "serverless-mocha-plugin"
]
```

## Usage

### Creating tests

When the plug-in is installed, tests are automatically created to the test/ directory
when creating new functions (only when using node 4.3 runtime).

Functions can also be added manually using the mocha-create command

```
sls function mocha-create functionName
```

If you want to run the tests against the real Lambda functions, you can pass the liveFunction object to wrapper.init().

```
  wrapper.init(liveFunction);
```

### Running tests

Tests can be run directly using Mocha (in which case it needs to be installed to your project or globally)
or using the mocha-run command

```
sls function mocha-run [-s stage] [-r region] [function1] [function2] [...]
```

To use a mocha reporter (e.g. json), use the -R switch. Reporter options can be passed with the -O switch.

If no function names are passed to mocha-run, all tests are run from the test/ directory

The default timeout for tests is 6 seconds. In case you need to apply a different timeout, that can be done in the test file 
using using this.timeout(milliseconds) in the define, after, before or it -blocks.

### Using own template for a test file

If you'd like to use your own template for a generated test file, create a sls-mocha-plugin-template.ejs file
in the test/ directory. Currently, there are two variables available for use:

- functionName - name of the function
- functionPath - path to the function

If you'd like to get more information on the template engine, you check documentation of the [EJS project](http://ejs.co/).


## Release History
* 2016/07/26 - v0.5.15 - Change to use lambda-wrapper runHandler by default (has ability to pass a default context)
* 2016/07/25 - v0.5.14 - Fix bug with mocha-create -T
* 2016/06/28 - v0.5.13 - Increase default test timeout to 6000ms
* 2016/06/27 - v0.5.12 - Add support for using template test files
* 2016/06/22 - v0.5.11 - Add support for running tests from live environment
* 2016/06/21 - v0.5.9 - Prompt for region / stage when running tests. Set environment separately for each test
* 2016/06/03 - v0.5.7 - Fix entangled function tests, Move wrapper.init into 'it' scope in generated mocha test code.
                      - Fix non-posix path separator in Windows.
                      - set environment variables correctly also when running all tests
* 2016/05/10 - v0.5.5 - Fix error message for mocha-create.
                      - Create tests with mocha-create without path in test name (as function create does)
* 2016/05/09 - v0.5.3 - Set environment variables during mocha-run (by AniKo)
                      - Add reporter options, return non-zero status for failures (by chouandy)
* 2016/04/09 - v0.5.0 - Initial version of module for serverless 0.5.*

## License

Copyright (c) 2016 [SC5](http://sc5.io/), licensed for users and contributors under MIT license.
https://github.com/SC5/serverless-mocha-plugin/blob/master/LICENSE


[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/SC5/serverless-mocha-plugin/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
<commit_msg>Update documentation<commit_after># Serverless Mocha Plugin

A Serverless Plugin for the [Serverless Framework](http://www.serverless.com) which
adds support for test driven development using [mocha](https://mochajs.org/)

**THIS PLUGIN REQUIRES SERVERLESS V0.5!**

Check out the 1.0 branch for the development version for Serverless 1.0

## Introduction

This plugins does the following:

* It will create test files when creating new serverless functions

* It provides commands to create and run tests manually

## Installation

In your project root, run:

```bash
npm install --save serverless-mocha-plugin
```

Add the plugin to `s-project.json`:

```json
"plugins": [
  "serverless-mocha-plugin"
]
```

## Usage

### Creating tests

When the plug-in is installed, tests are automatically created to the test/ directory
when creating new functions (only when using node 4.3 runtime).

Functions can also be added manually using the mocha-create command

```
sls function mocha-create functionName
```

If you want to run the tests against the real Lambda functions, you can pass the liveFunction object to wrapper.init().

```
  wrapper.init(liveFunction);
```

### Running tests

Tests can be run directly using Mocha (in which case it needs to be installed to your project or globally)
or using the mocha-run command

```
sls function mocha-run [-s stage] [-r region] [function1] [function2] [...]
```

To use a mocha reporter (e.g. json), use the -R switch. Reporter options can be passed with the -O switch.

If no function names are passed to mocha-run, all tests are run from the test/ directory

The default timeout for tests is 6 seconds. In case you need to apply a different timeout, that can be done in the test file 
using using this.timeout(milliseconds) in the define, after, before or it -blocks.

### Using own template for a test file

If you'd like to use your own template for a generated test file, create a sls-mocha-plugin-template.ejs file
in the test/ directory. Currently, there are two variables available for use:

- functionName - name of the function
- functionPath - path to the function

If you'd like to get more information on the template engine, you check documentation of the [EJS project](http://ejs.co/).


## Release History
* 2016/07/26 - v0.5.15 - Change to use lambda-wrapper runHandler by default (has ability to pass a default context)
* 2016/07/25 - v0.5.14 - Fix bug with mocha-create -T
* 2016/06/28 - v0.5.13 - Increase default test timeout to 6000ms
* 2016/06/27 - v0.5.12 - Add support for using template test files
* 2016/06/22 - v0.5.11 - Add support for running tests from live environment
* 2016/06/21 - v0.5.9 - Prompt for region / stage when running tests. Set environment separately for each test
* 2016/06/03 - v0.5.7 - Fix entangled function tests, Move wrapper.init into 'it' scope in generated mocha test code.
                      - Fix non-posix path separator in Windows.
                      - set environment variables correctly also when running all tests
* 2016/05/10 - v0.5.5 - Fix error message for mocha-create.
                      - Create tests with mocha-create without path in test name (as function create does)
* 2016/05/09 - v0.5.3 - Set environment variables during mocha-run (by AniKo)
                      - Add reporter options, return non-zero status for failures (by chouandy)
* 2016/04/09 - v0.5.0 - Initial version of module for serverless 0.5.*

## License

Copyright (c) 2016 [SC5](http://sc5.io/), licensed for users and contributors under MIT license.
https://github.com/SC5/serverless-mocha-plugin/blob/master/LICENSE


[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/SC5/serverless-mocha-plugin/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

{'fraction_non_alphanumeric': 0.091031149301826, 'fraction_numerical': 0.038399570354457575, 'mean_word_length': 3.4792543595911005, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 8, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '580754', 'n_tokens_mistral': 2359, 'n_tokens_neox': 2120, 'n_words': 947}