From 06cb0c8d223d16d269362481979dc5cee7ede4fd Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Fri, 17 Jan 2014 14:13:25 -0500 Subject: [PATCH] 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) --- zerver/tests/frontend/node/index.js | 21 +++++++++++++++++++-- zerver/tests/frontend/node/templates.js | 7 ++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/zerver/tests/frontend/node/index.js b/zerver/tests/frontend/node/index.js index f7501765f4..660cfc9a8a 100644 --- a/zerver/tests/frontend/node/index.js +++ b/zerver/tests/frontend/node/index.js @@ -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) { if (Handlebars.templates === undefined) { 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); }; diff --git a/zerver/tests/frontend/node/templates.js b/zerver/tests/frontend/node/templates.js index 8226df349b..403f5e2ed5 100644 --- a/zerver/tests/frontend/node/templates.js +++ b/zerver/tests/frontend/node/templates.js @@ -545,7 +545,8 @@ function render(template_name, args) { 'tutorial_reply', 'tutorial_stream', 'tutorial_subject', - 'tutorial_title' + 'tutorial_title', + 'tutorial_welcome' ]; var html = ''; _.each(tutorials, function (tutorial) { @@ -604,3 +605,7 @@ function render(template_name, args) { 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();