What is this?
This little Gulp plugin is used to run Mocha tests within a RUNNING Docker Container. It allows you to pass in Mocha CLI args to the test scripts. More on that later...
Installation
Simple: npm i -S gulp-mocha-docker
Docker Setup
You must have a local docker-compose.yaml
file properly setup. This plugin will look inside that file for the container name. See this example:
version: "2"
services:
web:
container_name: my-api
build:
context: .
dockerfile: Dockerfile-dev
environment:
NODE_ENV: development
volumes:
- ./:/usr/src/app
- /usr/src/app/node_modules
ports:
- "8080:8080"
command: node index.js
The plugin will look for a RUNNING container named my-api
and then call the Docker CLI to run the mocha script inside your container. We assume you have mocha and your tests available in your container using normal Mocha "defaults".
Gulp setup
Setup your gulp file like:
var gulp = require('gulp'),
gutil = require('gulp-util'),
mocha = require('gulp-mocha-docker');
gulp.task('test', function() {
return mocha().catch(err => gutil.log(gutil.colors.red(err)));
});
gulp.task('default', ['test']);
Usage
When you run gulp
(shown if setup like the above) you should see the script attempting to run test inside your running Docker container. You can also pass in CLI args to Mocha like these examples:
- Run a specific test file:
gulp test --test './test/my-test.js'
orgulp test -t './test/my-test.js'
- Grep tests to run:
gulp test -g 'super-awesome-test'
- Set the slow test threshold:
gulp test -s 200
... If you refer to the Mocha Usage Docs you can see other CLI args you can pass in! How slick is that