<commit_before>'use strict'

const mongoUri = process.env.MONGOLAB_URI || process.env.MONGOHQ_URL || process.env.MONGO_URI || null
const mongoose = require('mongoose')
const fs = require('fs')
const models = {}
const crowi = new (require(ROOT_DIR + '/lib/crowi'))(ROOT_DIR, process.env)

// Want fix...
crowi.config.crowi = { 'app:url': 'http://localhost:3000' }

mongoose.Promise = global.Promise

beforeAll(async () => {
  if (mongoUri) {
    await mongoose.connect(mongoUri)
    await mongoose.connection.db.dropDatabase()
  }
})

afterAll(async () => {
  if (mongoUri) {
    await mongoose.disconnect()
  }
})

// Setup Models
fs.readdirSync(MODEL_DIR).forEach(function(file) {
  if (file.match(/^(\w+)\.js$/)) {
    const name = RegExp.$1
    if (name === 'index') {
      return
    }
    const modelName = name.charAt(0).toUpperCase() + name.slice(1)
    models[modelName] = require(MODEL_DIR + '/' + file)(crowi)
  }
})

crowi.models = models

// create dummy Socket.IO server
crowi.getIo = function() {
  return {
    sockets: {
      emit: function(str, obj) {},
    },
  }
}

module.exports = {
  models: models,
  mongoose: mongoose,
}<commit_msg>Refact<commit_after>'use strict'

const mongoUri = process.env.MONGOLAB_URI || process.env.MONGOHQ_URL || process.env.MONGO_URI || null
const mongoose = require('mongoose')
const models = require(MODEL_DIR)
const Config = require(MODEL_DIR + '/config')
const crowi = new (require(ROOT_DIR + '/lib/crowi'))(ROOT_DIR, process.env)

// Want fix...
crowi.config.crowi = { 'app:url': 'http://localhost:3000' }

mongoose.Promise = global.Promise

beforeAll(async () => {
  if (mongoUri) {
    await mongoose.connect(mongoUri)
    await mongoose.connection.db.dropDatabase()
  }
})

afterAll(async () => {
  if (mongoUri) {
    await mongoose.disconnect()
  }
})

// Setup Models
models.Config = Config
for (let [modelName, model] of Object.entries(models)) {
  models[modelName] = model(crowi)
}
crowi.models = models

// create dummy Socket.IO server
crowi.getIo = function() {
  return {
    sockets: {
      emit: function(str, obj) {},
    },
  }
}

module.exports = {
  models,
  mongoose,
}
{'fraction_non_alphanumeric': 0.1642624476500698, 'fraction_numerical': 0.005118659841786877, 'mean_word_length': 3.6436285097192225, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2430024', 'n_tokens_mistral': 796, 'n_tokens_neox': 790, 'n_words': 149}