From 706b7b6fffe253fc1259671c39ebb4fe0ab47e31 Mon Sep 17 00:00:00 2001 From: tholulomo Date: Tue, 28 Feb 2023 21:09:55 -0500 Subject: [PATCH] feat(upgrade): #309 Setup coverage testing report for backend --- resfulservice/.nycrc.json | 10 ++++++++++ resfulservice/package.json | 5 +++-- resfulservice/spec/common/utils.js | 10 ++++++++++ resfulservice/spec/logger.js | 1 - resfulservice/spec/middlewares/isAuth.spec.js | 3 +-- resfulservice/spec/middlewares/isInternal.spec.js | 2 +- 6 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 resfulservice/.nycrc.json create mode 100644 resfulservice/spec/common/utils.js delete mode 100644 resfulservice/spec/logger.js diff --git a/resfulservice/.nycrc.json b/resfulservice/.nycrc.json new file mode 100644 index 00000000..ace035be --- /dev/null +++ b/resfulservice/.nycrc.json @@ -0,0 +1,10 @@ +{ + "all": true, + "include": ["src/"], + "exclude": ["**/*.spec.js"], + "check-coverage": true, + "statements": 31, + "branches": 22, + "functions": 21, + "lines": 31 +} \ No newline at end of file diff --git a/resfulservice/package.json b/resfulservice/package.json index 52f3e9f0..7deaff98 100644 --- a/resfulservice/package.json +++ b/resfulservice/package.json @@ -40,7 +40,7 @@ }, "scripts": { "start": "nodemon src/server.js --inspect", - "test": "mocha --recursive './spec/**/*.js'", + "test": "nyc --reporter=html --reporter=text --reporter=text-summary mocha --recursive './spec/**/*spec.js'", "lint": "eslint --fix src", "lint:test": "npm-run-all -s lint test", "start:prod": "node src/server.js", @@ -64,6 +64,7 @@ "eslint-plugin-node": "^11.1.0", "eslint-plugin-promise": "^6.0.0", "mocha": "^9.2.0", - "nodemon": "^2.0.15" + "nodemon": "^2.0.15", + "nyc": "^15.1.0" } } diff --git a/resfulservice/spec/common/utils.js b/resfulservice/spec/common/utils.js new file mode 100644 index 00000000..b563966e --- /dev/null +++ b/resfulservice/spec/common/utils.js @@ -0,0 +1,10 @@ +exports.logger = { + emerg: (log) => (console.log(log)), + alert: (log) => (console.log(log)), + crit: (log) => (console.log(log)), + error: (log) => (console.log(log)), + warning: (log) => (console.log(log)), + notice: (log) => (console.log(log)), + info: (log) => (console.log(log)), + debug: (log) => (console.log(log)) +}; diff --git a/resfulservice/spec/logger.js b/resfulservice/spec/logger.js deleted file mode 100644 index 17348d14..00000000 --- a/resfulservice/spec/logger.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = { error: (arg) => arg }; \ No newline at end of file diff --git a/resfulservice/spec/middlewares/isAuth.spec.js b/resfulservice/spec/middlewares/isAuth.spec.js index 69fab599..affebbba 100644 --- a/resfulservice/spec/middlewares/isAuth.spec.js +++ b/resfulservice/spec/middlewares/isAuth.spec.js @@ -1,8 +1,7 @@ const {expect} = require('chai'); const isAuth = require('../../src/middlewares/isAuth'); const {signToken} = require('../../src/utils/jwtService'); - -const logger = require('../logger'); +const { logger } = require('../common/utils'); describe('authValidation middleware service', function () { it('rejects unauthorized request', async function () { diff --git a/resfulservice/spec/middlewares/isInternal.spec.js b/resfulservice/spec/middlewares/isInternal.spec.js index 2d42823f..681ccb47 100644 --- a/resfulservice/spec/middlewares/isInternal.spec.js +++ b/resfulservice/spec/middlewares/isInternal.spec.js @@ -1,6 +1,6 @@ const { expect, should } = require('chai'); const { setInternal, getInternal } = require('../../src/middlewares/isInternal'); -const logger = require('../logger'); +const { logger } = require('../common/utils'); should();