Skip to content

Instantly share code, notes, and snippets.

@adriano-di-giovanni
Created September 30, 2016 07:05
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save adriano-di-giovanni/a9361f8c5ff6e97a6b22dd4c65c7bae9 to your computer and use it in GitHub Desktop.
Save adriano-di-giovanni/a9361f8c5ff6e97a6b22dd4c65c7bae9 to your computer and use it in GitHub Desktop.
dockerize mocha tests that depend on services
version: '2'
services:
test:
image: node:latest
working_dir: /app
volumes:
- .:/app
command:
npm run mocha
links:
- redis
- mysql
redis:
image: redis
mysql:
image: mysql
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
{
"scripts": {
"test": "docker-compose up test",
"posttest": "docker-compose stop redis mysql",
"mocha": "mocha --reporter spec ./test.js"
},
"devDependencies": {
"mocha": "^3.1.0"
},
"dependencies": {
"ioredis": "^2.4.0",
"mysql": "^2.11.1"
}
}
var Redis = require('ioredis')
var mysql = require('mysql')
describe('dockerize mocha tests that depend on services', function () {
it('should connect to redis', function () {
var client = new Redis(6379, 'redis', { lazyConnect: true })
return client.connect()
})
it('should connect to mysql', function (done) {
mysql.createConnection({
host: 'mysql',
user: 'root'
}).connect(done)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment