All files / koa/db index.js

46.67% Statements 7/15
27.27% Branches 3/11
50% Functions 3/6
46.67% Lines 7/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30    3x 3x     3x 9x         6x 6x                               3x
'use strict'
 
const path = require('path')
const fs = require('fs')
 
function readDBLink() {
  fs.readdirSync(__dirname)
    .filter(file => (file.indexOf('.') !== 0 && (file.split('.').slice(-1)[0] === 'js') && file !== 'index.js'))
    .forEach(file => {
      // files case: index.js users.js logs.js
      // const route = require(path.join(__dirname, file))
      // apiRouter.use(route.routes(),route.allowedMethods())
      const db = require(path.join(__dirname, file))
      process.on('SIGINT', function () {
        if (file === 'mongo.js') {
          db.disconnect(function (err) {
            console.log('------- mongodb client quit ------');
            process.exit(err ? 1 : 0)
          })
        } else if (file === 'redis.js') {
          db.redisCli.quit(function (err) {
            console.log('------ redis client quit ------');
            process.exit(err ? 1 : 0)
          })
        }
      })
    })
}
 
module.exports = readDBLink()