mirror of
https://github.com/zulip/zulip.git
synced 2025-11-14 10:57:58 +00:00
Ensure handlebars templates have test coverage.
The node tests will now throw an exception if you haven't at least compiled one of the handlebars templates as part or running template.js. This includes a one-line fix to include tutorial_welcome.handlebars. (imported from commit 51b4cae293d54c1f374a84623b4928519775e228)
This commit is contained in:
@@ -27,12 +27,29 @@ global.add_dependencies = function (dct) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function template_dir() {
|
||||||
|
return __dirname + '/../../../../static/templates/';
|
||||||
|
}
|
||||||
|
|
||||||
|
global.make_sure_all_templates_have_been_compiled = function () {
|
||||||
|
var dir = template_dir();
|
||||||
|
var fns = fs.readdirSync(dir).filter(function (fn) {
|
||||||
|
return (/\.handlebars/).test(fn);
|
||||||
|
});
|
||||||
|
|
||||||
|
_.each(fns, function (fn) {
|
||||||
|
var name = fn.split('.')[0];
|
||||||
|
if (!Handlebars.templates[name]) {
|
||||||
|
throw "The file " + fn + " has no test coverage.";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
global.use_template = function (name) {
|
global.use_template = function (name) {
|
||||||
if (Handlebars.templates === undefined) {
|
if (Handlebars.templates === undefined) {
|
||||||
Handlebars.templates = {};
|
Handlebars.templates = {};
|
||||||
}
|
}
|
||||||
var template_dir = __dirname+'/../../../../static/templates/';
|
var data = fs.readFileSync(template_dir() + name + '.handlebars').toString();
|
||||||
var data = fs.readFileSync(template_dir + name + '.handlebars').toString();
|
|
||||||
Handlebars.templates[name] = Handlebars.compile(data);
|
Handlebars.templates[name] = Handlebars.compile(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -545,7 +545,8 @@ function render(template_name, args) {
|
|||||||
'tutorial_reply',
|
'tutorial_reply',
|
||||||
'tutorial_stream',
|
'tutorial_stream',
|
||||||
'tutorial_subject',
|
'tutorial_subject',
|
||||||
'tutorial_title'
|
'tutorial_title',
|
||||||
|
'tutorial_welcome'
|
||||||
];
|
];
|
||||||
var html = '';
|
var html = '';
|
||||||
_.each(tutorials, function (tutorial) {
|
_.each(tutorials, function (tutorial) {
|
||||||
@@ -604,3 +605,7 @@ function render(template_name, args) {
|
|||||||
assert.equal(a.text().trim(), 'Narrow to private messages with Hamlet');
|
assert.equal(a.text().trim(), 'Narrow to private messages with Hamlet');
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
// By the end of this test, we should have compiled all our templates. Ideally,
|
||||||
|
// we will also have exercised them to some degree, but that's a little trickier
|
||||||
|
// to enforce.
|
||||||
|
global.make_sure_all_templates_have_been_compiled();
|
||||||
|
|||||||
Reference in New Issue
Block a user