2.0.5 • Published 22 days ago

mocha-pod v2.0.5

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
22 days ago

Mocha-Pod

Run your mocha tests using docker.

Mocha-Pod is a mocha plugin that takes over your npm run test, and runs your test suite using docker.

This ensures that anyone running the tests will have the same experience, no matter the development machine or if the tests are being ran as part of a CI build. Mocha-Pod also provides utilities to work with test configuration files and ensures the filesystem state is reset after each test.

  • Easy setup. Just add -r mocha-pod/attach to your mocha command. It will use some sensible configuration defaults.
  • Fully configurable through a .mochapod.yml at the root of your project.
  • CI compatible. Add MOCHAPOD_SKIP_SETUP to ensure the image build is skipped when running inside a CI system.
  • Additional filesystem utilities to setup/destroy the test environment (TODO).

Requirements

  • Mocha
  • Local or remote docker socket.

Usage

Add mocha-pod as a development dependency to your package.json.

npm i --save-dev mocha-pod

Add -r mocha-pod/attach to your mocha command inside your package.json.

Example:

// inside package.json
"scripts": {
  "test": "mocha -r mocha-pod/attach --reporter spec test/**/*.spec.js"
}

Or with typescript and ts-node.

// inside package.json
"scripts": {
	"test": "mocha -r ts-node/register -r lib/attach --reporter spec tests/**/*.spec.ts",
}

How does it work

Mocha-Pod makes use of mocha fixtures to first setup the environment. During this process the plugin will look for a Dockerfile (or Dockerfile.template) at the root directory of your project and will build an image using the directory contents. Any directives specified in .dockerignore will be respected and additional build configurations can be added under dockerBuildOpts in the Mocha-Pod configuration file.

After the build, the plugin will run a container passing npm run test as the command and passing MOCHAPOD_SKIP_SETUP=1 as an env var.

At this point a separate test process will be lauched, the plugin will run again, this time skipping the build step, and mocha root hooks will be ran before and after each test. These hooks will ensure the filesystem is reset to the initial condition (when the image was built).

If you need more control over how the tests are ran, you may chose to skip the container step and call npm run test directly inside your image build process. Make sure you set buildOnly: true in the configuration file, and set the MOCHAPOD_SKIP_SETUP=1 during this step (see our Dockerfile for an example).

Examples

This repository uses the Mocha-Pod plugin to run its own tests (TODO)

Configuration

See lib/config.ts for the full list of configuration options.

CI integration

When running tests inside a CI environment. Make sure the MOCHAPOD_SKIP_SETUP environment variable is set to true to prevent mocha pod from running the setup and going straight to running the tests.

2.0.5

22 days ago

2.0.4

2 months ago

2.0.3

2 months ago

2.0.2

2 months ago

2.0.1

3 months ago

2.0.0

3 months ago

0.10.5

11 months ago

0.10.6

11 months ago

0.10.7

11 months ago

0.10.8

11 months ago

0.10.2

1 year ago

0.10.3

1 year ago

0.10.4

1 year ago

0.8.5

2 years ago

0.8.4

2 years ago

0.8.7

1 year ago

0.8.6

2 years ago

0.10.1

1 year ago

0.10.0

1 year ago

0.8.3

2 years ago

0.8.2

2 years ago

0.9.0

1 year ago

0.7.1

2 years ago

0.5.0

2 years ago

0.7.0

2 years ago

0.8.1

2 years ago

0.8.0

2 years ago

0.4.1

2 years ago

0.6.0

2 years ago

0.4.0

2 years ago

0.3.3

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago