mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 01:26:12 +02:00
Enable require.main.require in tests (#6896)
This commit is contained in:
committed by
Barış Soner Uşaklı
parent
4caaa046d7
commit
9a32118418
6
app.js
6
app.js
@@ -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({
|
||||
|
||||
65
loader.js
65
loader.js
@@ -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(),
|
||||
});
|
||||
|
||||
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;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (err) {
|
||||
// No config detected, kickstart web installer
|
||||
fork('app');
|
||||
return;
|
||||
}
|
||||
|
||||
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(),
|
||||
});
|
||||
|
||||
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;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
10
require-main.js
Normal file
10
require-main.js
Normal file
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user