summaryrefslogtreecommitdiffstats
path: root/spec/precompiler.js
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2015-08-04 12:34:28 -0500
committerkpdecker <kpdecker@gmail.com>2015-08-04 12:34:28 -0500
commit0de8dac702f7b06161a0c5464a80bd327d708258 (patch)
treee1cb21d199f93dd0731590f1011dfc4110b14662 /spec/precompiler.js
parentd716fd01c546593d1f4c06cd7e1a6ba81a116586 (diff)
downloadhandlebars.js-0de8dac702f7b06161a0c5464a80bd327d708258.zip
handlebars.js-0de8dac702f7b06161a0c5464a80bd327d708258.tar.gz
handlebars.js-0de8dac702f7b06161a0c5464a80bd327d708258.tar.bz2
Add support for string and stdin precompilation
Fixes #1071
Diffstat (limited to 'spec/precompiler.js')
-rw-r--r--spec/precompiler.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/precompiler.js b/spec/precompiler.js
index 25c57a8..e1ad5ad 100644
--- a/spec/precompiler.js
+++ b/spec/precompiler.js
@@ -71,6 +71,11 @@ describe('precompiler', 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 missing name', function() {
+ shouldThrow(function() {
+ Precompiler.cli({templates: [{source: ''}], amd: true});
+ }, Handlebars.Exception, 'Name missing for template');
+ });
it('should throw when combining simple and directories', function() {
shouldThrow(function() {
Precompiler.cli({hasDirectory: true, templates: [1], simple: true});
@@ -82,6 +87,11 @@ describe('precompiler', function() {
Precompiler.cli({templates: [emptyTemplate], simple: true});
equal(log, 'simple\n');
});
+ it('should default to simple templates', function() {
+ Handlebars.precompile = function() { return 'simple'; };
+ Precompiler.cli({templates: [{source: ''}]});
+ equal(log, 'simple\n');
+ });
it('should output amd templates', function() {
Handlebars.precompile = function() { return 'amd'; };
Precompiler.cli({templates: [emptyTemplate], amd: true});
@@ -197,6 +207,42 @@ describe('precompiler', function() {
});
});
+ it('should accept string inputs', function(done) {
+ var opts = {string: ''};
+ Precompiler.loadTemplates(opts, function(err, opts) {
+ equal(opts.templates[0].name, undefined);
+ equal(opts.templates[0].source, '');
+ done(err);
+ });
+ });
+ it('should accept string array inputs', function(done) {
+ var opts = {string: ['', 'bar'], name: ['beep', 'boop']};
+ Precompiler.loadTemplates(opts, function(err, opts) {
+ equal(opts.templates[0].name, 'beep');
+ equal(opts.templates[0].source, '');
+ equal(opts.templates[1].name, 'boop');
+ equal(opts.templates[1].source, 'bar');
+ done(err);
+ });
+ });
+ it('should accept stdin input', function(done) {
+ var stdin = require('mock-stdin').stdin();
+ Precompiler.loadTemplates({string: '-'}, function(err, opts) {
+ equal(opts.templates[0].source, 'foo');
+ done(err);
+ });
+ stdin.send('fo');
+ stdin.send('o');
+ stdin.end();
+ });
+ it('error on name missing', function(done) {
+ var opts = {string: ['', 'bar']};
+ Precompiler.loadTemplates(opts, function(err) {
+ equal(err.message, 'Number of names did not match the number of string inputs');
+ done();
+ });
+ });
+
it('should complete when no args are passed', function(done) {
Precompiler.loadTemplates({}, function(err, opts) {
equal(opts.templates.length, 0);