From 81091f59572f5cf75756ddc141563662185073dc Mon Sep 17 00:00:00 2001 From: Jeff Jagoda Date: Thu, 31 Mar 2016 18:44:23 -0400 Subject: [PATCH] Report errors when loading helpers Fixes #73. --- lib/manager.js | 4 ++- test/manager.js | 34 ++++++++++++++++++++++ test/templates/invalid/helpers/bad1.module | 1 + test/templates/invalid/helpers/bad2.module | 3 ++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 test/templates/invalid/helpers/bad1.module create mode 100644 test/templates/invalid/helpers/bad2.module diff --git a/lib/manager.js b/lib/manager.js index fb164ad..d7d084b 100755 --- a/lib/manager.js +++ b/lib/manager.js @@ -257,7 +257,9 @@ internals.Manager.prototype._loadHelpers = function (engine) { engine.module.registerHelper(name, helper); } } - catch (err) { } + catch (err) { + console.log('WARNING: vision failed to load helper \'%s\': %s', file, err.message); + } } }); }); diff --git a/test/manager.js b/test/manager.js index 728f11e..16ab452 100755 --- a/test/manager.js +++ b/test/manager.js @@ -10,6 +10,7 @@ const Jade = require('jade'); const Lab = require('lab'); const Vision = require('..'); const Manager = require('../lib/manager'); +const Util = require('util'); // Declare internals @@ -1773,6 +1774,39 @@ describe('Manager', () => { }); }); + it('prints a warning message when helpers fail to load', (done) => { + + const buffer = []; + const oldLog = console.log; + + console.log = function () { + + const message = Util.format.apply(Util, arguments); + + buffer.push(message); + }; + + try { + new Manager({ + engines: { html: { module: Handlebars.create() } }, + relativeTo: 'test/templates', + path: 'valid', + helpersPath: 'invalid/helpers' + }); + } + finally { + console.log = oldLog; + } + + const output = buffer.join('\n'); + + expect(output).to.match(/^WARNING:/); + expect(output).to.contain('vision failed to load helper'); + expect(output).to.contain('invalid/helpers/bad1.module'); + expect(output).to.contain('invalid/helpers/bad2.module'); + done(); + }); + it('reuses cached compilation', (done) => { let gen = 0; diff --git a/test/templates/invalid/helpers/bad1.module b/test/templates/invalid/helpers/bad1.module new file mode 100644 index 0000000..a88f644 --- /dev/null +++ b/test/templates/invalid/helpers/bad1.module @@ -0,0 +1 @@ +this is an invalid helper diff --git a/test/templates/invalid/helpers/bad2.module b/test/templates/invalid/helpers/bad2.module new file mode 100644 index 0000000..838c860 --- /dev/null +++ b/test/templates/invalid/helpers/bad2.module @@ -0,0 +1,3 @@ +module.exports = funtcion (context) { + return context; +};