Enable `require.main.require` in tests (#6896)

v1.18.x
Peter Jaszkowiak 6 years ago committed by Barış Soner Uşaklı
parent 4caaa046d7
commit 9a32118418

@ -19,11 +19,7 @@
'use strict';
if (require.main !== module) {
require.main.require = function (path) {
return require(path);
};
}
require('./require-main');
var nconf = require('nconf');
nconf.argv().env({

@ -200,39 +200,40 @@ function killWorkers() {
}
fs.open(pathToConfig, 'r', function (err) {
if (!err) {
if (nconf.get('daemon') !== 'false' && nconf.get('daemon') !== false) {
if (file.existsSync(pidFilePath)) {
try {
var pid = fs.readFileSync(pidFilePath, { encoding: 'utf-8' });
process.kill(pid, 0);
process.exit();
} catch (e) {
fs.unlinkSync(pidFilePath);
}
}
require('daemon')({
stdout: process.stdout,
stderr: process.stderr,
cwd: process.cwd(),
});
if (err) {
// No config detected, kickstart web installer
fork('app');
return;
}
fs.writeFileSync(pidFilePath, process.pid);
if (nconf.get('daemon') !== 'false' && nconf.get('daemon') !== false) {
if (file.existsSync(pidFilePath)) {
try {
var pid = fs.readFileSync(pidFilePath, { encoding: 'utf-8' });
process.kill(pid, 0);
process.exit();
} catch (e) {
fs.unlinkSync(pidFilePath);
}
}
async.series([
Loader.init,
Loader.displayStartupMessages,
Loader.start,
], function (err) {
if (err) {
console.error('[loader] Error during startup');
throw err;
}
require('daemon')({
stdout: process.stdout,
stderr: process.stderr,
cwd: process.cwd(),
});
} else {
// No config detected, kickstart web installer
fork('app');
fs.writeFileSync(pidFilePath, process.pid);
}
async.series([
Loader.init,
Loader.displayStartupMessages,
Loader.start,
], function (err) {
if (err) {
console.error('[loader] Error during startup');
throw err;
}
});
});

@ -0,0 +1,10 @@
'use strict';
// this forces `require.main.require` to always be relative to this directory
// this allows plugins to use `require.main.require` to reference NodeBB modules
// without worrying about multiple parent modules
if (require.main !== module) {
require.main.require = function (path) {
return require(path);
};
}

@ -5,6 +5,7 @@
* ATTENTION: testing db is flushed before every use!
*/
require('../../require-main');
var async = require('async');
var path = require('path');
@ -13,7 +14,6 @@ var url = require('url');
global.env = process.env.TEST_ENV || 'production';
var errorText;
var packageInfo = require('../../package');
var winston = require('winston');
@ -43,7 +43,7 @@ var testDbConfig = nconf.get('test_database');
var productionDbConfig = nconf.get(dbType);
if (!testDbConfig) {
errorText = 'test_database is not defined';
const errorText = 'test_database is not defined';
winston.info(
'\n===========================================================\n' +
'Please, add parameters for test database in config.json\n' +
@ -86,7 +86,7 @@ if (!testDbConfig) {
if (testDbConfig.database === productionDbConfig.database &&
testDbConfig.host === productionDbConfig.host &&
testDbConfig.port === productionDbConfig.port) {
errorText = 'test_database has the same config as production db';
const errorText = 'test_database has the same config as production db';
winston.error(errorText);
throw new Error(errorText);
}

Loading…
Cancel
Save