From 44186edbc5c6be24071c703503dd82e1b1832682 Mon Sep 17 00:00:00 2001 From: muxator Date: Tue, 14 Apr 2020 01:10:19 +0200 Subject: [PATCH] tests: remove loadSettings.js for backend tests. The old loadSettings.js was a way of customizing settings upon load, because the Settings module did not offer this functionality. But it did not work well, since all the default settings were not loaded. Let's get rid of loadSettings.js for the bulk of the tests (the "backend" specs). For the "container" specs, we'll keep it in place until/if we rewrite Settings.js making it less brittle. --- src/node/utils/Settings.js | 9 ++++++- tests/backend/loadSettings.js | 26 -------------------- tests/backend/specs/api/api.js | 2 +- tests/backend/specs/api/characterEncoding.js | 2 +- tests/backend/specs/api/chat.js | 2 +- tests/backend/specs/api/pad.js | 2 +- tests/backend/specs/api/sessionsAndGroups.js | 2 +- tests/container/loadSettings.js | 13 +++++++--- 8 files changed, 23 insertions(+), 35 deletions(-) delete mode 100644 tests/backend/loadSettings.js diff --git a/src/node/utils/Settings.js b/src/node/utils/Settings.js index e44a01282..2d519d0ab 100644 --- a/src/node/utils/Settings.js +++ b/src/node/utils/Settings.js @@ -1,6 +1,13 @@ /** - * The Settings Modul reads the settings out of settings.json and provides + * The Settings module reads the settings out of settings.json and provides * this information to the other modules + * + * TODO muxator 2020-04-14: + * + * 1) get rid of the reloadSettings() call at module loading; + * 2) provide a factory method that configures the settings module at runtime, + * reading the file name either from command line parameters, from a function + * argument, or falling back to a default. */ /* diff --git a/tests/backend/loadSettings.js b/tests/backend/loadSettings.js deleted file mode 100644 index e1ab27d90..000000000 --- a/tests/backend/loadSettings.js +++ /dev/null @@ -1,26 +0,0 @@ -/* - * ACHTUNG: there is a copied & modified version of this file in - * /tests/container/loadSettings.js - * - * TODO: unify those two files, and merge in a single one. - */ - -var jsonminify = require(__dirname+"/../../src/node_modules/jsonminify"); -const fs = require('fs'); - -function loadSettings(){ - var settingsStr = fs.readFileSync(__dirname+"/../../settings.json").toString(); - // try to parse the settings - try { - if(settingsStr) { - settingsStr = jsonminify(settingsStr).replace(",]","]").replace(",}","}"); - var settings = JSON.parse(settingsStr); - - return settings; - } - }catch(e){ - console.error("whoops something is bad with settings"); - } -} - -exports.loadSettings = loadSettings; diff --git a/tests/backend/specs/api/api.js b/tests/backend/specs/api/api.js index 745c79905..0b372de85 100644 --- a/tests/backend/specs/api/api.js +++ b/tests/backend/specs/api/api.js @@ -9,7 +9,7 @@ const assert = require('assert'); const supertest = require(__dirname + '/../../../../src/node_modules/supertest'); const fs = require('fs'); -const settings = require(__dirname + '/../../loadSettings').loadSettings(); +const settings = require(__dirname + '/../../../../src/node/utils/Settings'); const api = supertest('http://' + settings.ip + ':' + settings.port); const path = require('path'); diff --git a/tests/backend/specs/api/characterEncoding.js b/tests/backend/specs/api/characterEncoding.js index 5c6b16231..83145089f 100644 --- a/tests/backend/specs/api/characterEncoding.js +++ b/tests/backend/specs/api/characterEncoding.js @@ -7,7 +7,7 @@ const assert = require('assert'); const supertest = require(__dirname+'/../../../../src/node_modules/supertest'); const fs = require('fs'); -const settings = require(__dirname+'/../../loadSettings').loadSettings(); +const settings = require(__dirname + '/../../../../src/node/utils/Settings'); const api = supertest('http://'+settings.ip+":"+settings.port); const path = require('path'); const async = require(__dirname+'/../../../../src/node_modules/async'); diff --git a/tests/backend/specs/api/chat.js b/tests/backend/specs/api/chat.js index 2bcd9783a..e2ce59b1c 100644 --- a/tests/backend/specs/api/chat.js +++ b/tests/backend/specs/api/chat.js @@ -1,7 +1,7 @@ var assert = require('assert') supertest = require(__dirname+'/../../../../src/node_modules/supertest'), fs = require('fs'), - settings = require(__dirname+'/../../loadSettings').loadSettings(), + settings = require(__dirname + '/../../../../src/node/utils/Settings'), api = supertest('http://'+settings.ip+":"+settings.port), path = require('path'); diff --git a/tests/backend/specs/api/pad.js b/tests/backend/specs/api/pad.js index d8fde5ada..c1b8d49df 100644 --- a/tests/backend/specs/api/pad.js +++ b/tests/backend/specs/api/pad.js @@ -8,7 +8,7 @@ const assert = require('assert'); const supertest = require(__dirname+'/../../../../src/node_modules/supertest'); const fs = require('fs'); -const settings = require(__dirname+'/../../loadSettings').loadSettings(); +const settings = require(__dirname + '/../../../../src/node/utils/Settings'); const api = supertest('http://'+settings.ip+":"+settings.port); const path = require('path'); const async = require(__dirname+'/../../../../src/node_modules/async'); diff --git a/tests/backend/specs/api/sessionsAndGroups.js b/tests/backend/specs/api/sessionsAndGroups.js index 961cb2df9..cbc6e0a1a 100644 --- a/tests/backend/specs/api/sessionsAndGroups.js +++ b/tests/backend/specs/api/sessionsAndGroups.js @@ -1,7 +1,7 @@ var assert = require('assert') supertest = require(__dirname+'/../../../../src/node_modules/supertest'), fs = require('fs'), - settings = require(__dirname+'/../../loadSettings').loadSettings(), + settings = require(__dirname + '/../../../../src/node/utils/Settings'), api = supertest('http://'+settings.ip+":"+settings.port), path = require('path'); diff --git a/tests/container/loadSettings.js b/tests/container/loadSettings.js index 4ac445fe9..4a1c46021 100644 --- a/tests/container/loadSettings.js +++ b/tests/container/loadSettings.js @@ -1,8 +1,15 @@ /* - * ACHTUNG: this file was copied & modified from the analogous - * /tests/backend/loadSettings.js + * ACHTUNG: this file is a hack used to load "settings.json.docker" instead of + * "settings.json", since in its present form the Settings module does + * not allow it. + * This is a remnant of an analogous file that was placed in + * /tests/backend/loadSettings.js * - * TODO: unify those two files, and merge in a single one. + * TODO: modify the Settings module: + * 1) no side effects on module load + * 2) write a factory method that loads a configuration file (taking the + * file name from the command line, a function argument, or falling + * back to a default) */ var jsonminify = require(__dirname+"/../../src/node_modules/jsonminify");