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:
parent
58ba14c188
commit
4a47e8d0a8
4 changed files with 7 additions and 7 deletions
|
@ -31,7 +31,7 @@ module.exports = {
|
|||
* @returns {Object} routes.yaml in JSON format
|
||||
*/
|
||||
get: function get() {
|
||||
return SettingsLoader('routes');
|
||||
return SettingsLoader.loadSettingsSync('routes');
|
||||
},
|
||||
|
||||
getDefaultHash: () => {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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/);
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue