Crear un ambiente de pruebas
Correr pruebas dentro de tus contenedores
Live debugging con VS Code
$ docker
$ git clone https://github.com/AxelMonroyX/testing-live-debugging-with-docker.git
$ cd testing-live-debugging-with-docker/
$ cat Dockerfile
FROM node:6
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app/
RUN npm install -g nodemon
RUN npm install
ENV DEBUG myapp:*
COPY . /usr/src/app
EXPOSE 3000
CMD [ "npm", "start" ]
$ cat docker-compose.yml
version: '2'
services:
whale-docker:
build: .
ports:
- "3000:3000"
volumes:
- ./:/usr/src/app
working_dir: /usr/src/app
depends_on:
- mongo
links:
- mongo:db
command: /bin/bash -c "npm start"
mongo:
image: mongo:3
ports:
- "27017:27017"
volumes:
- ./docker/develop/data:/data/db
$ docker-compose up -d
http://localhost:3000
$ npm install chai chai-http mocha --save-dev
$ mkdir test
$ cd test
$ touch tuArchivoDePruebasNuevo.js
//Require the dev-dependencies
let chai = require('chai');
let chaiHttp = require('chai-http');
let server = require('../app');
let should = chai.should();
chai.use(chaiHttp);
describe('Routes', () => {
describe('/GET index', () => {
it('it should GET an html', (done) => {
chai.request(server)
.get('/')
.end((err, res) => {
res.should.have.status(200);
done();
});
});
});
});
"scripts": {
"test": "mocha --timeout 10000"
}
$ docker exec -it testinglivedebuggingwithdocker_whale-docker_1 npm test
// Obsoleto
"scripts": {
"start": "nodemon --debug ./bin/www",
"test": "mocha --timeout 10000"
}
// Actual
"scripts": {
"start": "nodemon --inspect ./bin/www",
"test": "mocha --timeout 10000"
}
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach",
"port": 5858
},
{
"name": "Docker: Attach to Node",
"type": "node",
"request": "attach",
"port": 9229,
"address": "localhost",
"localRoot": "${workspaceRoot}",
"remoteRoot": "/usr/src/app"
}
]
}