Skip to content

Commit

Permalink
Merge pull request #8 from alexvndre/feature/ci
Browse files Browse the repository at this point in the history
Add CI
  • Loading branch information
alexvndre committed Nov 14, 2017
2 parents 33af5ff + 6b694e5 commit c75be8c
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"presets": ["es2015"]
"presets": ["env"]
}
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: node_js
node_js:
- "8"
env:
- NODE_ENV=test

before_script:
- cp ./.env.dist ./.env
script:
- ./node_modules/.bin/bithound check git@github.com:alexvndre/expressjs-starter-pack.git
- make test
after_script:
- make test-coveralls
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.0.8] - 2017-11-14
### Added
- Add CI
- Add [Travis](https://travis-ci.org/alexvndre/expressjs-starter-pack)
- Add [Coveralls](https://coveralls.io/github/alexvndre/expressjs-starter-pack)
- Add [Bithound](https://www.bithound.io/github/alexvndre/expressjs-starter-pack/master)
### Changed
- Update linter es2015 to env
- Lint tests ok

## [0.0.7] - 2017-11-13
### Added
- Add Docker
Expand Down
16 changes: 14 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,21 @@ start: ## start the web server
test: ## launch tests
@echo " > Testing the project"
@$(MAKE) -s build
@export PORT=0 && export NODE_ENV=test && $(MOCHA) --require babel-core/register --recursive --exit
@export PORT=0 && \
export NODE_ENV=test && \
$(MOCHA) --require babel-core/register --recursive --exit

test-coverage: ## launch tests with coverage
@echo " > Testing with coverage"
@$(MAKE) -s build
@export PORT=0 && export NODE_ENV=test && $(BABEL_NODE) $(BABEL_ISTANBUL) cover $(MOCHA_) --report html --report text --check-coverage -- --recursive
@export PORT=0 && \
export NODE_ENV=test && \
$(BABEL_NODE) $(BABEL_ISTANBUL) cover $(MOCHA_) --report html --report text --check-coverage -- --recursive --exit

test-coveralls: ## launch tests with coverage and send to coveralls
@export PORT=0 && \
export NODE_ENV=test && \
export COVERALLS_SERVICE_NAME=travis-ci && \
$(BABEL_NODE) $(BABEL_ISTANBUL) cover $(MOCHA_) --report lcovonly --check-coverage -- --recursive --exit && \
cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && \
rm -rf ./coverage
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Express.js starter pack
======
# Express.js starter pack

[![Build Status](https://travis-ci.org/alexvndre/expressjs-starter-pack.svg?branch=master)](https://travis-ci.org/alexvndre/expressjs-starter-pack)
[![bitHound Overall Score](https://www.bithound.io/github/alexvndre/expressjs-starter-pack/badges/score.svg)](https://www.bithound.io/github/alexvndre/expressjs-starter-pack)
[![Coverage Status](https://coveralls.io/repos/github/alexvndre/expressjs-starter-pack/badge.svg?branch=feature%2Fci)](https://coveralls.io/github/alexvndre/expressjs-starter-pack?branch=feature%2Fci)

A ready to use [Express.js](https://expressjs.com) solution.

Expand All @@ -23,7 +26,7 @@ Run tests to verify the installation.

### Run the project (without [Docker](https://www.docker.com/))

The project is available on [http://127.0.0.1:<PORT>](http://127.0.0.1:<PORT>).
The project is available on `http://127.0.0.1:<PORT>`.

`$ make start`

Expand All @@ -42,10 +45,3 @@ You can check that your image is listed by Docker with `$ docker images`.
Check if the image is running with `$ docker ps`. You can read the app output with `$ docker logs <CONTAINER_ID>`.
If you need to run an app command, `$ docker exec -it <CONTAINER_ID> /bin/bash`.
To kill it: `$ docker kill <CONTAINER_ID>`.

### TODO

* Command sample ([commander](https://github.com/tj/commander.js))
* External HTTP calls ([request](https://github.com/request/request))
* Mock test ([sinon.js](http://sinonjs.org))
* BDD ([mongodb](https://www.npmjs.com/package/mongodb) and other wrappers)
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
"babel-core": "^6.24.0",
"babel-eslint": "^8.0.1",
"babel-istanbul": "^0.12.2",
"babel-preset-es2015": "^6.24.0",
"babel-preset-env": "^1.6.1",
"bithound": "^1.7.0",
"chai": "^4.1.2",
"chai-http": "^3.0.0",
"coveralls": "^3.0.0",
"eslint": "^4.10.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.2.0",
Expand All @@ -35,6 +37,7 @@
"istanbul": "^0.4.5",
"mocha": "^4.0.1",
"mocha-istanbul": "^0.3.0",
"mocha-lcov-reporter": "^1.3.0",
"npm-check-updates": "^2.13.0"
},
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions src/helper/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Logger {
],
});

if (process.env.NODE_ENV === 'local') {
if (process.env.NODE_ENV === 'local' || process.env.NODE_ENV === 'test') {
this._logger.add(winston.transports.Console, {
level: 'info',
timestamp: () => (new Date().toISOString()),
Expand All @@ -21,13 +21,13 @@ class Logger {
}

info(message, meta) {
if (process.env.NODE_ENV === 'local') {
if (process.env.NODE_ENV === 'local' || process.env.NODE_ENV === 'test') {
this._logger.log('info', message, meta);
}
}

error(message, meta) {
if (process.env.NODE_ENV === 'local') {
if (process.env.NODE_ENV === 'local' || process.env.NODE_ENV === 'test') {
this._logger.log('error', message, meta);
}
}
Expand Down
5 changes: 3 additions & 2 deletions test/app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { describe, it } from 'mocha';
import chai from 'chai';
import chaiHttp from 'chai-http';
import server from './../src/server';

const should = chai.should();
chai.should();

chai.use(chaiHttp);

Expand All @@ -14,7 +15,7 @@ describe('app', () => {
.set('Content-Type', 'application/json')
.send('toto')
.end((err, res) => {
res.should.have.status(500);
res.status.should.eql(500);
res.body.should.have.property('code');
res.body.code.should.eql(500);
res.body.should.have.property('message');
Expand Down
7 changes: 3 additions & 4 deletions test/controller/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { describe, it } from 'mocha';
import chai from 'chai';
import chaiHttp from 'chai-http';
import server from './../../src/server';

const should = chai.should();
chai.should();

chai.use(chaiHttp);

Expand All @@ -13,10 +14,8 @@ describe('controller/index', () => {
.get('/not-found-route')
.send()
.end((err, res) => {
res.should.have.status(404);
res.body.should.have.property('code');
res.status.should.eql(404);
res.body.code.should.eql(404);
res.body.should.have.property('message');
res.body.message.should.eql('Not found');
done();
});
Expand Down
15 changes: 8 additions & 7 deletions test/controller/v1/resource.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { describe, it } from 'mocha';
import chai from 'chai';
import chaiHttp from 'chai-http';
import server from './../../../src/server';

const should = chai.should();
chai.should();

chai.use(chaiHttp);

Expand All @@ -13,7 +14,7 @@ describe('controller/v1/resource', () => {
.get('/v1/resources')
.send()
.end((err, res) => {
res.should.have.status(200);
res.status.should.eql(200);
res.body.should.be.a('array');
res.body.forEach((item) => {
item.should.be.a('object');
Expand All @@ -29,7 +30,7 @@ describe('controller/v1/resource', () => {
.set('Content-Type', 'application/json')
.send({ test: 'test' })
.end((err, res) => {
res.should.have.status(400);
res.status.should.eql(400);
res.body.should.be.a('array');
res.body[0].should.have.property('code');
res.body[0].should.have.property('message');
Expand All @@ -46,7 +47,7 @@ describe('controller/v1/resource', () => {
.set('Content-Type', 'application/json')
.send({ name: 'test' })
.end((err, res) => {
res.should.have.status(201);
res.status.should.eql(201);
res.body.should.be.a('object');
res.body.should.have.property('id');
res.body.should.have.property('name');
Expand All @@ -61,7 +62,7 @@ describe('controller/v1/resource', () => {
.get('/v1/resources/1')
.send()
.end((err, res) => {
res.should.have.status(200);
res.status.should.eql(200);
res.body.should.be.a('object');
res.body.should.have.property('id');
res.body.should.have.property('name');
Expand All @@ -76,7 +77,7 @@ describe('controller/v1/resource', () => {
.put('/v1/resources/1')
.send({ name: 'test' })
.end((err, res) => {
res.should.have.status(200);
res.status.should.eql(200);
res.body.should.be.a('object');
res.body.should.have.property('id');
res.body.should.have.property('name');
Expand All @@ -91,7 +92,7 @@ describe('controller/v1/resource', () => {
.delete('/v1/resources/1')
.send()
.end((err, res) => {
res.should.have.status(204);
res.status.should.eql(204);
done();
});
});
Expand Down

0 comments on commit c75be8c

Please sign in to comment.