diff options
Diffstat (limited to 'spec/precompiler.js')
-rw-r--r-- | spec/precompiler.js | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/spec/precompiler.js b/spec/precompiler.js index 7cd1ffd..57fc280 100644 --- a/spec/precompiler.js +++ b/spec/precompiler.js @@ -10,9 +10,12 @@ describe('precompiler', function() { Precompiler = require('../lib/precompiler'); var log, - logFunction; + logFunction, + + precompile; beforeEach(function() { + precompile = Handlebars.precompile; logFunction = console.log; log = ''; console.log = function() { @@ -20,6 +23,7 @@ describe('precompiler', function() { }; }); afterEach(function() { + Handlebars.precompile = precompile; console.log = logFunction; }); @@ -37,4 +41,43 @@ describe('precompiler', function() { Precompiler.cli({templates: ['foo']}); }, Handlebars.Exception, 'Unable to open template file "foo"'); }); + it('should throw when combining simple and minimized', function() { + shouldThrow(function() { + Precompiler.cli({templates: [__dirname], simple: true, min: true}); + }, Handlebars.Exception, 'Unable to minimze simple output'); + }); + it('should throw when combining simple and multiple templates', function() { + shouldThrow(function() { + Precompiler.cli({templates: [__dirname + '/artifacts/empty.handlebars', __dirname + '/artifacts/empty.handlebars'], simple: true}); + }, Handlebars.Exception, 'Unable to output multiple templates in simple mode'); + }); + it('should throw when combining simple and directories', function() { + shouldThrow(function() { + Precompiler.cli({templates: [__dirname], simple: true}); + }, Handlebars.Exception, 'Unable to output multiple templates in simple mode'); + }); + it('should enumerate directories by extension', function() { + Precompiler.cli({templates: [__dirname + '/artifacts'], extension: 'hbs'}); + equal(/'example_2'/.test(log), true); + log = ''; + + Precompiler.cli({templates: [__dirname + '/artifacts'], extension: 'handlebars'}); + equal(/'empty'/.test(log), true); + equal(/'example_1'/.test(log), true); + }); + it('should output simple templates', function() { + Handlebars.precompile = function() { return 'simple'; }; + Precompiler.cli({templates: [__dirname + '/artifacts/empty.handlebars'], simple: true, extension: 'handlebars'}); + equal(log, 'simple\n'); + }); + it('should output amd templates', function() { + Handlebars.precompile = function() { return 'amd'; }; + Precompiler.cli({templates: [__dirname + '/artifacts/empty.handlebars'], amd: true, extension: 'handlebars'}); + equal(/template\(amd\)/.test(log), true); + }); + it('should output commonjs templates', function() { + Handlebars.precompile = function() { return 'commonjs'; }; + Precompiler.cli({templates: [__dirname + '/artifacts/empty.handlebars'], commonjs: true, extension: 'handlebars'}); + equal(/template\(commonjs\)/.test(log), true); + }); }); |