Skip to content

Instantly share code, notes, and snippets.

@basicallydan
Created September 8, 2014 08:53
Show Gist options
  • Save basicallydan/486f3cfe8e8a1ad7f7b3 to your computer and use it in GitHub Desktop.
Save basicallydan/486f3cfe8e8a1ad7f7b3 to your computer and use it in GitHub Desktop.
Handlebars for Mocha with Browserify
/*
* This is useful if you are using Mocha for your tests, Browserify for Modules and Handlebars for templates.
* It should be set up before running tests
* Note that require.extensions is depreciated: http://nodejs.org/api/globals.html#globals_require_extensions
* It is based on https://gist.github.com/akre54/11183020
*/
var Handlebars = require('handlebars');
var fs = require('fs');
require.extensions['.hbs'] = function (module, filename) {
var compiled;
var raw = fs.readFileSync(filename, 'utf8');
compiled = Handlebars.compile(raw);
module.exports = compiled;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment