From de23c10caf07783c0e603deaa15016542e14465e Mon Sep 17 00:00:00 2001 From: Dinuka De Silva Date: Tue, 3 Oct 2017 18:32:19 +0530 Subject: [PATCH] gh-6: Adding some test cases and setup with `mocha` and `nyc` for code coverage This fixes #6 --- .gitignore | 2 ++ server/package.json | 10 ++++++++-- server/src/app.js | 4 +++- server/test/spec.js | 28 ++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 server/test/spec.js diff --git a/.gitignore b/.gitignore index 3c3629e..8d76113 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ node_modules +.nyc_output +.idea diff --git a/server/package.json b/server/package.json index 5d9b7eb..2bed88e 100644 --- a/server/package.json +++ b/server/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "start": "./node_modules/nodemon/bin/nodemon.js src/app.js", - "test": "echo \"Error: no test specified\" && exit 1" + "test": "nyc mocha" }, "keywords": [], "author": "", @@ -13,8 +13,14 @@ "dependencies": { "body-parser": "^1.18.1", "cors": "^2.8.4", - "express": "^4.15.4", + "express": "^4.16.1", "morgan": "^1.8.2", "nodemon": "^1.12.1" + }, + "devDependencies": { + "expect.js": "^0.3.1", + "mocha": "^4.0.0", + "nyc": "^11.2.1", + "supertest": "^3.0.0" } } diff --git a/server/src/app.js b/server/src/app.js index 0a483e6..92c2032 100644 --- a/server/src/app.js +++ b/server/src/app.js @@ -85,4 +85,6 @@ app.get('/post/:id', (req, res) => { }) }) -app.listen(process.env.PORT || 8081) +app.listen(process.env.PORT || 8081); + +module.exports = app; diff --git a/server/test/spec.js b/server/test/spec.js new file mode 100644 index 0000000..cc48ba2 --- /dev/null +++ b/server/test/spec.js @@ -0,0 +1,28 @@ +var request = require("supertest"); +var expect = require("expect.js"); +var server = require("../src/app"); + +describe("MEVN-boilerplate - TESTS", function () { + after(function () { + process.exit(); + }); + describe("posts", function () { + it("GET /posts", function (done) { + request(server) + .get('/posts') + .expect(200, done); + }); + it("GET /post/:id", function () { + //TODO + }); + it("POST /add_post", function () { + //TODO + }); + it("PUT /posts/:id", function () { + //TODO + }); + it("DELETE /posts/:id", function () { + //TODO + }); + }); +});