Node.js e
MongoDB
http://www.luiztools.com.br
Tape
CRONOGRAMA
Tape
Tape
● Testes unitários
● Continuous Integration - CI
● Continuous Delivery - CD
nano /cinema-microservice/movies-
service/src/config/mongodb.test.js
Preparando
Tape
const test = require('tape');
const mongodb = require('./mongodb');
function runTests(){
test('MongoDB Connection', (t) => {
mongodb.connect((err, conn) => {
t.assert(conn, "Connection established");
t.end();
});
})
mongodb.test.js
Tape
test('MongoDB Disconnection', (t) => {
t.assert(mongodb.disconnect(), "Disconnected");
t.end();
})
}
module.exports = { runTests }
mongodb.test.js
Tape
nano /cinema-microservice/movies-
service/src/index.test.js
//index.test.js
require("dotenv-safe").load();
require("./config/mongodb.test").runTests();
index.test.js
Tape
{
"name": "movie-service",
"version": "1.0.0",
"description": "Service to provide movies",
"main": "index.js",
"scripts": {
"start": "node index",
"test": "node index.test | tap-spec"
},
"author": "",
"license": "ISC",
...
packages.json
Tape
Dúvidas?
Exercícios
1 Crie um módulo de calculadora
2 Crie os testes unitários da calculadora
3 Configure para que funcione via 'npm test'
Obrigado!

Curso de Node.js e MongoDB - 15