Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

lambda-mocha-runner

corybill15ISC1.0.1

Run mocha driven integration tests inside of an AWS Lambda.

StriveNine, Strive9, S9, Mocha, Mocha Programmatically, AWS, AWS Mocha, AWS Lambda, AWS Mocha Lambda

readme

Mocha Lambda Runner

Easily run mocha tests programmatically from a lambda. This makes running integration tests from an AWS Lambda very simple.

Install

npm install lambda-mocha-runner

Contract

Runner.run takes two parameters:

  1. mochaOptions - This gets passed directly into Mocha. For More Information.
  2. testDir - The path to the directory with your tests. This should be relative to the root directory of your lambda.

    Example

    ` const Runner = require("lambda-mocha-runner");

class Lambda { static run(event, context, callback) { const context = { mochaOptions: {}, testDir: "path/to/test/files" };

Runner.run(context)
  .then((response) => callback(null, response))
  .catch((err) => callback(err));

} }

module.exports = Lambda;


## Sample Response Object
**All Tests Passing**

{ suite: { type: "suite", isPassing: true, numPassing: 2, numFailing: 0 }, tests: [ { type: "test", isPassing: true, durationInMillis: 100, testTitle: "Given When Then it should do 1", stackTrace: "" }, { type: "test", isPassing: true, durationInMillis: context.duration, testTitle: "Given When Then it should do 2", stackTrace: "" } ] };


**One Test Failing**

{ suite: { type: "suite", isPassing: false, numPassing: 1, numFailing: 1 }, tests: [ { type: "test", isPassing: true, durationInMillis: 100, testTitle: "Given When Then it should do 1", stackTrace: "" }, { type: "test", isPassing: false, durationInMillis: context.duration, testTitle: "Given When Then it should do 2", stackTrace: "Some Strack Trace Will Be Here" } ] }; `