mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
do not output server logs when testing, ability to run tests and server separately
This commit is contained in:
@@ -97,9 +97,10 @@
|
||||
"test": "gulp lint && npm run test:api-v3:unit && npm run test:api-v3:integration",
|
||||
"test:api-v2:unit": "mocha test/server_side",
|
||||
"test:api-v2:integration": "mocha test/api/v2 --recursive",
|
||||
"test:api-v3": "mocha test/api/v3 --recursive",
|
||||
"test:api-v3": "npm run test:api-v3:unit && npm run test:api-v3:integration",
|
||||
"test:api-v3:unit": "mocha test/api/v3/unit --recursive",
|
||||
"test:api-v3:integration": "mocha test/api/v3/integration --recursive",
|
||||
"test:api-v3:integration:separate-server": "LOAD_SERVER=0 mocha test/api/v3/integration --recursive",
|
||||
"test:api-legacy": "istanbul cover -i \"website/src/**\" --dir coverage/api ./node_modules/mocha/bin/_mocha test/api-legacy",
|
||||
"test:common": "mocha test/common",
|
||||
"test:content": "mocha test/content",
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
/* eslint-disable no-undef */
|
||||
/* eslint-disable global-require */
|
||||
/* eslint-disable no-process-env */
|
||||
//------------------------------
|
||||
// Global modules
|
||||
//------------------------------
|
||||
@@ -12,14 +14,24 @@ global.sinon = require('sinon');
|
||||
global.sandbox = sinon.sandbox.create();
|
||||
|
||||
import nconf from 'nconf';
|
||||
import mongoose from 'mongoose';
|
||||
import Q from 'q';
|
||||
|
||||
//------------------------------
|
||||
// Load nconf for unit tests
|
||||
//------------------------------
|
||||
require('../../website/src/libs/api-v3/setupNconf')('./config.json.example');
|
||||
nconf.set('NODE_DB_URI', 'mongodb://localhost/habitrpg_test');
|
||||
nconf.set('NODE_ENV', 'test');
|
||||
// We require src/server and npt src/index because
|
||||
// 1. nconf is already setup
|
||||
// 2. we don't need clustering
|
||||
require('../../website/src/server');
|
||||
if (process.env.LOAD_SERVER === '0') { // when the server is in a different process we simply connect to mongoose
|
||||
require('../../website/src/libs/api-v3/setupNconf')('./config.json');
|
||||
// Use Q promises instead of mpromise in mongoose
|
||||
mongoose.Promise = Q.Promise;
|
||||
mongoose.connect(nconf.get('NODE_DB_URI'));
|
||||
} else { // When running tests and the server in the same process
|
||||
require('../../website/src/libs/api-v3/setupNconf')('./config.json.example');
|
||||
nconf.set('NODE_DB_URI', 'mongodb://localhost/habitrpg_test');
|
||||
nconf.set('NODE_ENV', 'test');
|
||||
nconf.set('IS_TEST', true);
|
||||
// We require src/server and npt src/index because
|
||||
// 1. nconf is already setup
|
||||
// 2. we don't need clustering
|
||||
require('../../website/src/server');
|
||||
}
|
||||
|
||||
@@ -4,12 +4,15 @@ import winston from 'winston';
|
||||
import nconf from 'nconf';
|
||||
|
||||
const IS_PROD = nconf.get('IS_PROD');
|
||||
const IS_TEST = nconf.get('IS_TEST');
|
||||
|
||||
let logger = new winston.Logger();
|
||||
|
||||
if (IS_PROD) {
|
||||
// TODO production logging, use loggly
|
||||
// log errors to console too
|
||||
} else if (IS_TEST) {
|
||||
// Do not log anything when testing
|
||||
} else {
|
||||
logger
|
||||
.add(winston.transports.Console, {
|
||||
|
||||
@@ -13,4 +13,5 @@ export default function setupNconf (file) {
|
||||
|
||||
nconf.set('IS_PROD', nconf.get('NODE_ENV') === 'production');
|
||||
nconf.set('IS_DEV', nconf.get('NODE_ENV') === 'development');
|
||||
nconf.set('IS_TEST', nconf.get('NODE_ENV') === 'test');
|
||||
}
|
||||
|
||||
@@ -515,7 +515,7 @@ export let model = mongoose.model('Group', schema);
|
||||
|
||||
// initialize tavern if !exists (fresh installs)
|
||||
// do not run when testing as it's handled by the tests and can easily cause a race condition
|
||||
if (nconf.get('NODE_ENV') !== 'test') {
|
||||
if (nconf.get('IS_TEST')) {
|
||||
model.count({_id: 'habitrpg'}, (err, ct) => {
|
||||
if (err) throw err;
|
||||
if (ct > 0) return;
|
||||
|
||||
Reference in New Issue
Block a user