mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Fixed circular dependency warning for the proxy service (#12746)
no-issue The handlebars template module is required by the proxy service, as part of the definition of the proxy service's module.exports. By destructuring the i18n property from the proxy service at the time the template module is loaded, the i18n property was always undefined, as the module.exports of the proxy service had not been set. Bypassing the proxy, and requiring the i18n module directly eliminates the circular dependency. * Refactored handlebars template tests to use proxy Since this module is intended to be used via the proxy, we should test it in the same way. We have uncovered a circular dependency issue, which would not be possible to catch in tests unless the tests were to go via the proxy. * Added breaking test for handlebars template function This test highlights the issue caused by a circular dependency, we are unable to throw an IncorrectUsageError because i18n is undefined.
This commit is contained in:
parent
970b0e62b4
commit
fac62cd698
2 changed files with 11 additions and 5 deletions
|
@ -3,7 +3,7 @@ const templates = {};
|
|||
const _ = require('lodash');
|
||||
const errors = require('@tryghost/errors');
|
||||
const hbs = require('../engine');
|
||||
const {i18n} = require('../../proxy');
|
||||
const {i18n} = require('../../../../server/lib/common');
|
||||
|
||||
// Execute a template helper
|
||||
// All template helpers are register as partial view.
|
||||
|
|
|
@ -1,14 +1,20 @@
|
|||
const should = require('should');
|
||||
const hbs = require('../../../../../core/frontend/services/themes/engine');
|
||||
const template = require('../../../../../core/frontend/services/themes/handlebars/template');
|
||||
const errors = require('@tryghost/errors');
|
||||
const proxy = require('../../../../../core/frontend/services/proxy');
|
||||
|
||||
describe('Helpers Template', function () {
|
||||
it('can execute a template', function () {
|
||||
hbs.registerPartial('test', '<h1>Hello {{name}}</h1>');
|
||||
proxy.hbs.registerPartial('test', '<h1>Hello {{name}}</h1>');
|
||||
|
||||
const safeString = template.execute('test', {name: 'world'});
|
||||
const safeString = proxy.templates.execute('test', {name: 'world'});
|
||||
|
||||
should.exist(safeString);
|
||||
safeString.should.have.property('string').and.equal('<h1>Hello world</h1>');
|
||||
});
|
||||
|
||||
it('will throw an IncorrectUsageError if the partial does not exist', function () {
|
||||
should.throws(() => {
|
||||
proxy.templates.execute('non-existent');
|
||||
}, errors.IncorrectUsageError);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue