|
|
|
@@ -4,6 +4,7 @@ var fs = require('fs'); |
|
|
|
var path = require('path'); |
|
|
|
var _files = path.join(__dirname, '_files'); |
|
|
|
var cliTxt = path.resolve(_files, 'cli.txt'); |
|
|
|
var cliPartialsTxt = path.resolve(_files, 'cli_with_partials.txt'); |
|
|
|
var moduleVersion = require('../package').version; |
|
|
|
|
|
|
|
var exec = require('child_process').exec; |
|
|
|
@@ -12,15 +13,6 @@ describe('Mustache CLI', function () { |
|
|
|
|
|
|
|
var expectedOutput; |
|
|
|
|
|
|
|
before(function(done) { |
|
|
|
fs.readFile(cliTxt, function onFsEnd(err, data) { |
|
|
|
if (err) return done(err); |
|
|
|
|
|
|
|
expectedOutput = data.toString(); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it('writes syntax hints into stderr when runned with wrong number of arguments', function(done) { |
|
|
|
exec('bin/mustache', function(err, stdout, stderr) { |
|
|
|
assert.notEqual(stderr.indexOf('Syntax'), -1); |
|
|
|
@@ -49,36 +41,76 @@ describe('Mustache CLI', function () { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it('writes rendered template into stdout when successfull', function(done) { |
|
|
|
exec('bin/mustache test/_files/cli.json test/_files/cli.mustache', function(err, stdout, stderr) { |
|
|
|
assert.equal(err, null); |
|
|
|
assert.equal(stderr, ''); |
|
|
|
assert.equal(stdout, expectedOutput); |
|
|
|
done(); |
|
|
|
describe("without partials", function(){ |
|
|
|
before(function(done) { |
|
|
|
fs.readFile(cliTxt, function onFsEnd(err, data) { |
|
|
|
if (err) return done(err); |
|
|
|
|
|
|
|
expectedOutput = data.toString(); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it('reads view data from stdin when first argument equals "-"', function(done){ |
|
|
|
exec('cat test/_files/cli.json | bin/mustache - test/_files/cli.mustache', function(err, stdout, stderr) { |
|
|
|
assert.equal(err, null); |
|
|
|
assert.equal(stderr, ''); |
|
|
|
assert.equal(stdout, expectedOutput); |
|
|
|
done(); |
|
|
|
it('writes rendered template into stdout when successfull', function(done) { |
|
|
|
exec('bin/mustache test/_files/cli.json test/_files/cli.mustache', function(err, stdout, stderr) { |
|
|
|
assert.equal(err, null); |
|
|
|
assert.equal(stderr, ''); |
|
|
|
assert.equal(stdout, expectedOutput); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it('writes it couldnt find template into stderr when second argument doesnt resolve to a file', function(done) { |
|
|
|
exec('bin/mustache test/_files/cli.json test/_files/non-existing-template.mustache', function(err, stdout, stderr) { |
|
|
|
assert.notEqual(stderr.indexOf('Could not find file: test/_files/non-existing-template.mustache'), -1); |
|
|
|
done(); |
|
|
|
it('reads view data from stdin when first argument equals "-"', function(done){ |
|
|
|
exec('cat test/_files/cli.json | bin/mustache - test/_files/cli.mustache', function(err, stdout, stderr) { |
|
|
|
assert.equal(err, null); |
|
|
|
assert.equal(stderr, ''); |
|
|
|
assert.equal(stdout, expectedOutput); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it('writes it couldnt find view into stderr when first argument doesnt resolve to a file', function(done) { |
|
|
|
exec('bin/mustache test/_files/non-existing-view.json test/_files/cli.mustache', function(err, stdout, stderr) { |
|
|
|
assert.notEqual(stderr.indexOf('Could not find file: test/_files/non-existing-view.json'), -1); |
|
|
|
done(); |
|
|
|
it('writes it couldnt find template into stderr when second argument doesnt resolve to a file', function(done) { |
|
|
|
exec('bin/mustache test/_files/cli.json test/_files/non-existing-template.mustache', function(err, stdout, stderr) { |
|
|
|
assert.notEqual(stderr.indexOf('Could not find file: test/_files/non-existing-template.mustache'), -1); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it('writes it couldnt find view into stderr when first argument doesnt resolve to a file', function(done) { |
|
|
|
exec('bin/mustache test/_files/non-existing-view.json test/_files/cli.mustache', function(err, stdout, stderr) { |
|
|
|
assert.notEqual(stderr.indexOf('Could not find file: test/_files/non-existing-view.json'), -1); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe("with partials", function(){ |
|
|
|
before(function(done) { |
|
|
|
fs.readFile(cliPartialsTxt, function onFsEnd(err, data) { |
|
|
|
if (err) return done(err); |
|
|
|
|
|
|
|
expectedOutput = data.toString(); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it('writes rendered template with partials into stdout', function(done) { |
|
|
|
exec('bin/mustache test/_files/cli_with_partials.json test/_files/cli_with_partials.mustache -p test/_files/cli.mustache -p test/_files/comments.mustache', function(err, stdout, stderr) { |
|
|
|
assert.equal(err, null); |
|
|
|
assert.equal(stderr, ''); |
|
|
|
assert.equal(stdout, expectedOutput); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it('writes rendered template with partials when partials args before required args', function(done) { |
|
|
|
exec('bin/mustache -p test/_files/cli.mustache -p test/_files/comments.mustache test/_files/cli_with_partials.json test/_files/cli_with_partials.mustache', function(err, stdout, stderr) { |
|
|
|
assert.equal(err, null); |
|
|
|
assert.equal(stderr, ''); |
|
|
|
assert.equal(stdout, expectedOutput); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}) |
|
|
|
}); |