Skip to content

Commit

Permalink
Added tests and coverage (#3)
Browse files Browse the repository at this point in the history
* Added tests & coverage
  • Loading branch information
ankitjain28may authored Jul 14, 2020
1 parent 9d670e3 commit 86b2ee6
Show file tree
Hide file tree
Showing 14 changed files with 5,586 additions and 777 deletions.
8 changes: 6 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ jobs:
- checkout
- node/install-packages
- run:
name: Running npm pretest
name: Running npm test
command: |
npm run pretest
npm run test
- run:
name: Codecov coverage
command: |
npm run coverage
- setup_remote_docker:
version: 18.06.0-ce
- run:
Expand Down
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
.env
.git
trash
trash
coverage
1 change: 1 addition & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ env:
browser: true
commonjs: true
es2020: true
jest: true
extends:
- standard
parserOptions:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
.env
.git
trash
coverage
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ before_install:
- git rev-parse HEAD > ./commit.txt
script:
- npm install
- npm run pretest
- npm run test
- npm run coverage
- docker build -t heroku-dockerize:travis .
- docker images
deploy:
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ FROM node:14-alpine
RUN apk add --no-cache --update curl bash
WORKDIR /app

ARG NODE_ENV=development
ARG PORT=3000
ENV PORT=$PORT

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Heroku Dockerize

[![Build Status](https://travis-ci.org/ankitjain28may/heroku-dockerize.svg?branch=master)](https://travis-ci.org/ankitjain28may/heroku-dockerize) [![CircleCI](https://circleci.com/gh/ankitjain28may/heroku-dockerize.svg?style=svg)](https://circleci.com/gh/ankitjain28may/heroku-dockerize)
[![Build Status](https://travis-ci.org/ankitjain28may/heroku-dockerize.svg?branch=master)](https://travis-ci.org/ankitjain28may/heroku-dockerize) [![CircleCI](https://circleci.com/gh/ankitjain28may/heroku-dockerize.svg?style=svg)](https://circleci.com/gh/ankitjain28may/heroku-dockerize) [![codecov](https://codecov.io/gh/ankitjain28may/heroku-dockerize/branch/master/graph/badge.svg?token=9hF1I1wBxl)](https://codecov.io/gh/ankitjain28may/heroku-dockerize)
6 changes: 5 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ networks:

services:
web:
build: .
build:
context: .
args:
- NODE_ENV=production
container_name: heroku-dockerize-web

networks:
- internal
ports:
Expand Down
2 changes: 2 additions & 0 deletions heroku.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ setup:
build:
docker:
web: Dockerfile
config:
NODE_ENV: production
run:
web: node index.js
16 changes: 14 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const redis = require('redis')
const path = require('path')
const app = express()

const port = process.env.PORT || 3000
const redisUrl = process.env.REDIS_URL || 'redis://localhost:6379'
const client = redis.createClient(redisUrl)

Expand Down Expand Up @@ -50,4 +49,17 @@ app.post('/dummy/:id', (req, res) => {
})
})

app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`))
app.delete('/dummy/:id', (req, res) => {
client.del(req.params.id, (err, reply) => {
if (err) {
return res.send(err)
}
if (reply === 1) {
return res.send('Deleted Successfully!')
} else {
return res.send('Cannot delete')
}
})
})

module.exports = app
Loading

0 comments on commit 86b2ee6

Please sign in to comment.