Created
September 30, 2016 07:05
-
-
Save adriano-di-giovanni/a9361f8c5ff6e97a6b22dd4c65c7bae9 to your computer and use it in GitHub Desktop.
dockerize mocha tests that depend on services
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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