0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Changed settings loader module API signature

refs https://linear.app/tryghost/issue/CORE-35/refactor-route-and-redirect-settings

- It was not clear from the module signature/usages that the default method is executing synchronously. The change makes it explicit. Knowing if the method is synchronous is helpful to stop possible pefr bottlenecks!
This commit is contained in:
Naz 2021-09-23 14:38:19 +02:00 committed by naz
parent 58ba14c188
commit 4a47e8d0a8
4 changed files with 7 additions and 7 deletions

View file

@ -31,7 +31,7 @@ module.exports = {
* @returns {Object} routes.yaml in JSON format
*/
get: function get() {
return SettingsLoader('routes');
return SettingsLoader.loadSettingsSync('routes');
},
getDefaultHash: () => {

View file

@ -61,7 +61,7 @@ const loadSettings = async (setting) => {
* @param {String} setting the requested settings as defined in setting knownSettings
* @returns {Object} settingsFile
*/
module.exports = function loadSettingsSync(setting) {
module.exports.loadSettingsSync = function loadSettingsSync(setting) {
const {fileName, contentPath, filePath} = getSettingFilePath(setting);
try {

View file

@ -47,7 +47,7 @@ describe('UNIT > Settings Service loader:', function () {
loadSettings.__set__('yamlParser', yamlParserStub);
loadSettings.__set__('validate', validateStub);
const setting = loadSettings('goodroutes');
const setting = loadSettings.loadSettingsSync('goodroutes');
should.exist(setting);
setting.should.be.an.Object().with.properties('routes', 'collections', 'taxonomies');
// There are 4 files in the fixtures folder, but only 1 supported and valid yaml files
@ -65,7 +65,7 @@ describe('UNIT > Settings Service loader:', function () {
loadSettings.__set__('yamlParser', yamlParserStub);
try {
loadSettings('goodroutes');
loadSettings.loadSettingsSync('goodroutes');
done(new Error('Loader should fail'));
} catch (err) {
should.exist(err);
@ -94,7 +94,7 @@ describe('UNIT > Settings Service loader:', function () {
loadSettings.__set__('yamlParser', yamlParserStub);
try {
loadSettings('routes');
loadSettings.loadSettingsSync('routes');
done(new Error('Loader should fail'));
} catch (err) {
err.message.should.match(/Error trying to load YAML setting for routes from/);

View file

@ -29,7 +29,7 @@ describe('UNIT > Settings Service:', function () {
it('returns settings object for `routes`', function () {
settingsLoaderStub.returns(settingsStubFile);
settings.__set__('SettingsLoader', settingsLoaderStub);
settings.__set__('SettingsLoader.loadSettingsSync', settingsLoaderStub);
const result = settings.get();
should.exist(result);
@ -39,7 +39,7 @@ describe('UNIT > Settings Service:', function () {
it('passes SettingsLoader error through', function (done) {
settingsLoaderStub.throws(new errors.GhostError({message: 'oops'}));
settings.__set__('SettingsLoader', settingsLoaderStub);
settings.__set__('SettingsLoader.loadSettingsSync', settingsLoaderStub);
try {
settings.get();