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:
Steve Howell
2014-01-17 14:13:25 -05:00
parent 8b09d4da6c
commit 06cb0c8d22
2 changed files with 25 additions and 3 deletions

View File

@@ -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);
}; };

View File

@@ -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();