Skip to content

Commit

Permalink
Report errors when loading helpers
Browse files Browse the repository at this point in the history
Fixes hapijs#73.
  • Loading branch information
jagoda committed Mar 31, 2016
1 parent 43155a6 commit 81091f5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/manager.js
Expand Up @@ -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);
}
}
});
});
Expand Down
34 changes: 34 additions & 0 deletions test/manager.js
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions test/templates/invalid/helpers/bad1.module
@@ -0,0 +1 @@
this is an invalid helper
3 changes: 3 additions & 0 deletions test/templates/invalid/helpers/bad2.module
@@ -0,0 +1,3 @@
module.exports = funtcion (context) {
return context;
};

0 comments on commit 81091f5

Please sign in to comment.