mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +01:00
init express/webserver for tests
This commit is contained in:
@@ -7,7 +7,9 @@ module.exports = function (db, module) {
|
|||||||
|
|
||||||
module.flushdb = function (callback) {
|
module.flushdb = function (callback) {
|
||||||
callback = callback || helpers.noop;
|
callback = callback || helpers.noop;
|
||||||
db.dropDatabase(callback);
|
db.dropDatabase(function (err) {
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exists = function (key, callback) {
|
module.exists = function (key, callback) {
|
||||||
|
|||||||
@@ -5,12 +5,13 @@
|
|||||||
|
|
||||||
(function (module) {
|
(function (module) {
|
||||||
'use strict';
|
'use strict';
|
||||||
/*global require, before*/
|
/*global require, before, __dirname*/
|
||||||
|
|
||||||
var path = require('path'),
|
var async = require('async');
|
||||||
nconf = require('nconf'),
|
var path = require('path');
|
||||||
winston = require('winston'),
|
var nconf = require('nconf');
|
||||||
errorText;
|
var winston = require('winston');
|
||||||
|
var errorText;
|
||||||
|
|
||||||
|
|
||||||
nconf.file({ file: path.join(__dirname, '../../config.json') });
|
nconf.file({ file: path.join(__dirname, '../../config.json') });
|
||||||
@@ -22,11 +23,11 @@
|
|||||||
relative_path: ''
|
relative_path: ''
|
||||||
});
|
});
|
||||||
|
|
||||||
var dbType = nconf.get('database'),
|
var dbType = nconf.get('database');
|
||||||
testDbConfig = nconf.get('test_database'),
|
var testDbConfig = nconf.get('test_database');
|
||||||
productionDbConfig = nconf.get(dbType);
|
var productionDbConfig = nconf.get(dbType);
|
||||||
|
|
||||||
if(!testDbConfig){
|
if (!testDbConfig){
|
||||||
errorText = 'test_database is not defined';
|
errorText = 'test_database is not defined';
|
||||||
winston.info(
|
winston.info(
|
||||||
'\n===========================================================\n' +
|
'\n===========================================================\n' +
|
||||||
@@ -59,10 +60,9 @@
|
|||||||
throw new Error(errorText);
|
throw new Error(errorText);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( testDbConfig.database === productionDbConfig.database &&
|
if (testDbConfig.database === productionDbConfig.database &&
|
||||||
testDbConfig.host === productionDbConfig.host &&
|
testDbConfig.host === productionDbConfig.host &&
|
||||||
testDbConfig.port === productionDbConfig.port
|
testDbConfig.port === productionDbConfig.port) {
|
||||||
){
|
|
||||||
errorText = 'test_database has the same config as production db';
|
errorText = 'test_database has the same config as production db';
|
||||||
winston.error(errorText);
|
winston.error(errorText);
|
||||||
throw new Error(errorText);
|
throw new Error(errorText);
|
||||||
@@ -70,38 +70,38 @@
|
|||||||
|
|
||||||
nconf.set(dbType, testDbConfig);
|
nconf.set(dbType, testDbConfig);
|
||||||
|
|
||||||
var db = require('../../src/database'),
|
var db = require('../../src/database');
|
||||||
meta = require('../../src/meta');
|
var meta = require('../../src/meta');
|
||||||
|
|
||||||
before(function (done) {
|
before(function (done) {
|
||||||
db.init(function (err) {
|
async.waterfall([
|
||||||
if (err) {
|
function (next) {
|
||||||
return done(err);
|
db.init(next);
|
||||||
}
|
},
|
||||||
|
function (next) {
|
||||||
//Clean up
|
db.flushdb(next);
|
||||||
db.flushdb(function (err) {
|
},
|
||||||
if(err) {
|
function (next) {
|
||||||
winston.error(err);
|
|
||||||
throw new Error(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
winston.info('test_database flushed');
|
winston.info('test_database flushed');
|
||||||
|
meta.configs.init(next);
|
||||||
|
},
|
||||||
|
function (next) {
|
||||||
|
nconf.set('url', nconf.get('base_url') + (nconf.get('use_port') ? ':' + nconf.get('port') : '') + nconf.get('relative_path'));
|
||||||
|
nconf.set('core_templates_path', path.join(__dirname, '../../src/views'));
|
||||||
|
nconf.set('base_templates_path', path.join(nconf.get('themes_path'), 'nodebb-theme-vanilla/templates'));
|
||||||
|
nconf.set('theme_templates_path', meta.config['theme:templates'] ? path.join(nconf.get('themes_path'), meta.config['theme:id'], meta.config['theme:templates']) : nconf.get('base_templates_path'));
|
||||||
|
|
||||||
meta.configs.init(function () {
|
var webserver = require('../../src/webserver');
|
||||||
nconf.set('url', nconf.get('base_url') + (nconf.get('use_port') ? ':' + nconf.get('port') : '') + nconf.get('relative_path'));
|
var sockets = require('../../src/socket.io');
|
||||||
nconf.set('core_templates_path', path.join(__dirname, '../../src/views'));
|
sockets.init(webserver.server);
|
||||||
nconf.set('base_templates_path', path.join(nconf.get('themes_path'), 'nodebb-theme-vanilla/templates'));
|
|
||||||
nconf.set('theme_templates_path', meta.config['theme:templates'] ? path.join(nconf.get('themes_path'), meta.config['theme:id'], meta.config['theme:templates']) : nconf.get('base_templates_path'));
|
|
||||||
|
|
||||||
var webserver = require('../../src/webserver'),
|
require('../../src/notifications').init();
|
||||||
sockets = require('../../src/socket.io');
|
require('../../src/user').startJobs();
|
||||||
sockets.init(webserver.server);
|
|
||||||
|
|
||||||
done();
|
webserver.listen();
|
||||||
});
|
next();
|
||||||
});
|
}
|
||||||
});
|
], done);
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = db;
|
module.exports = db;
|
||||||
|
|||||||
@@ -3,10 +3,6 @@
|
|||||||
|
|
||||||
var winston = require('winston');
|
var winston = require('winston');
|
||||||
|
|
||||||
process.on('uncaughtException', function (err) {
|
|
||||||
winston.error('Encountered error while running test suite: ' + err.message);
|
|
||||||
});
|
|
||||||
|
|
||||||
var assert = require('assert'),
|
var assert = require('assert'),
|
||||||
async = require('async'),
|
async = require('async'),
|
||||||
db = require('./mocks/databasemock');
|
db = require('./mocks/databasemock');
|
||||||
@@ -244,7 +240,9 @@ describe('User', function () {
|
|||||||
|
|
||||||
it('.send() should create a new reset code and reset password', function (done) {
|
it('.send() should create a new reset code and reset password', function (done) {
|
||||||
User.reset.send('reset@me.com', function (err, code) {
|
User.reset.send('reset@me.com', function (err, code) {
|
||||||
assert.ifError(err);
|
if (err) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user