Commit 6d507401 by Andrew Nesbitt

Merge pull request #355 from blopker/master

Fix boolean paramaters
parents 40bdc985 7e1f9c58
...@@ -31,14 +31,16 @@ var optimist = require('optimist') ...@@ -31,14 +31,16 @@ var optimist = require('optimist')
}) })
.options('watch', { .options('watch', {
describe: 'Watch a directory or file', describe: 'Watch a directory or file',
alias: 'w' alias: 'w',
type: 'boolean'
}) })
.options('output', { .options('output', {
describe: 'Output css file', describe: 'Output css file',
alias: 'o' alias: 'o'
}) })
.options('stdout', { .options('stdout', {
describe: 'Print the resulting CSS to stdout' describe: 'Print the resulting CSS to stdout',
type: 'boolean'
}) })
.options('help', { .options('help', {
describe: 'Print usage info', describe: 'Print usage info',
......
...@@ -27,6 +27,8 @@ var expectedSampleNoComments = '#navbar {\n\ ...@@ -27,6 +27,8 @@ var expectedSampleNoComments = '#navbar {\n\
var expectedSampleCustomImagePath = 'body {\n\ var expectedSampleCustomImagePath = 'body {\n\
background-image: url("/path/to/images/image.png"); }\n'; background-image: url("/path/to/images/image.png"); }\n';
var sampleScssPath = path.join(__dirname, 'sample.scss');
describe('cli', function() { describe('cli', function() {
it('should print help when run with no arguments', function(done) { it('should print help when run with no arguments', function(done) {
exec('node ' + cliPath, function(err, stdout, stderr) { exec('node ' + cliPath, function(err, stdout, stderr) {
...@@ -78,7 +80,7 @@ describe('cli', function() { ...@@ -78,7 +80,7 @@ describe('cli', function() {
}); });
it('should compile with the --output-style', function(done){ it('should compile with the --output-style', function(done){
var emitter = cli(['--output-style', 'compressed', path.join(__dirname, 'sample.scss')]); var emitter = cli(['--output-style', 'compressed', sampleScssPath]);
emitter.on('error', done); emitter.on('error', done);
emitter.on('write', function(err, file, css){ emitter.on('write', function(err, file, css){
assert.equal(css, expectedSampleCompressed); assert.equal(css, expectedSampleCompressed);
...@@ -87,7 +89,7 @@ describe('cli', function() { ...@@ -87,7 +89,7 @@ describe('cli', function() {
}); });
it('should compile with the --source-comments option', function(done){ it('should compile with the --source-comments option', function(done){
var emitter = cli(['--source-comments', 'none', path.join(__dirname, 'sample.scss')]); var emitter = cli(['--source-comments', 'none', sampleScssPath]);
emitter.on('error', done); emitter.on('error', done);
emitter.on('write', function(err, file, css){ emitter.on('write', function(err, file, css){
assert.equal(css, expectedSampleNoComments); assert.equal(css, expectedSampleNoComments);
...@@ -106,7 +108,7 @@ describe('cli', function() { ...@@ -106,7 +108,7 @@ describe('cli', function() {
it('should write the output to the file specified with the --output option', function(done){ it('should write the output to the file specified with the --output option', function(done){
var resultPath = path.join(__dirname, '../output.css'); var resultPath = path.join(__dirname, '../output.css');
var emitter = cli(['--output', resultPath, path.join(__dirname, 'sample.scss')]); var emitter = cli(['--output', resultPath, sampleScssPath]);
emitter.on('error', done); emitter.on('error', done);
emitter.on('write', function(){ emitter.on('write', function(){
fs.exists(resultPath, function(exists) { fs.exists(resultPath, function(exists) {
...@@ -116,8 +118,36 @@ describe('cli', function() { ...@@ -116,8 +118,36 @@ describe('cli', function() {
}); });
}); });
it('should write to stdout with the --stdout option', function(done){
var emitter = cli(['--stdout', sampleScssPath]);
emitter.on('error', done);
emitter.on('log', function(css){
assert.equal(css, expectedSampleNoComments);
done();
});
});
it('should not exit with the --watch option', function(done){
var command = cliPath + ' --watch ' + sampleScssPath;
var child = exec('node ' + command);
var exited = false;
child.on('exit', function() {
exited = true;
});
setTimeout(function() {
if (exited){
throw new Error('Watch ended too early!');
} else {
child.kill();
done();
}
}, 100);
});
it('should compile with the --source-map option', function(done){ it('should compile with the --source-map option', function(done){
var emitter = cli([path.join(__dirname, 'sample.scss'), '--source-map']); var emitter = cli([sampleScssPath, '--source-map']);
emitter.on('error', done); emitter.on('error', done);
emitter.on('write-source-map', function(err, file) { emitter.on('write-source-map', function(err, file) {
assert.equal(file, path.join(__dirname, '../sample.css.map')); assert.equal(file, path.join(__dirname, '../sample.css.map'));
...@@ -125,6 +155,7 @@ describe('cli', function() { ...@@ -125,6 +155,7 @@ describe('cli', function() {
assert(exists); assert(exists);
}); });
}); });
emitter.on('done', function() { emitter.on('done', function() {
fs.unlink(path.join(__dirname, '../sample.css.map'), function() { fs.unlink(path.join(__dirname, '../sample.css.map'), function() {
fs.unlink(path.join(__dirname, '../sample.css'), function() { fs.unlink(path.join(__dirname, '../sample.css'), function() {
...@@ -135,7 +166,7 @@ describe('cli', function() { ...@@ -135,7 +166,7 @@ describe('cli', function() {
}); });
it('should compile with the --source-map option with specific filename', function(done){ it('should compile with the --source-map option with specific filename', function(done){
var emitter = cli([path.join(__dirname, 'sample.scss'), '--source-map', path.join(__dirname, '../sample.map')]); var emitter = cli([sampleScssPath, '--source-map', path.join(__dirname, '../sample.map')]);
emitter.on('error', done); emitter.on('error', done);
emitter.on('write-source-map', function(err, file) { emitter.on('write-source-map', function(err, file) {
assert.equal(file, path.join(__dirname, '../sample.map')); assert.equal(file, path.join(__dirname, '../sample.map'));
...@@ -153,7 +184,7 @@ describe('cli', function() { ...@@ -153,7 +184,7 @@ describe('cli', function() {
}); });
it('should compile a sourceMap if --source-comments="map", but the --source-map option is excluded', function(done){ it('should compile a sourceMap if --source-comments="map", but the --source-map option is excluded', function(done){
var emitter = cli([path.join(__dirname, 'sample.scss'), '--source-comments', 'map']); var emitter = cli([sampleScssPath, '--source-comments', 'map']);
emitter.on('error', done); emitter.on('error', done);
emitter.on('write-source-map', function(err, file) { emitter.on('write-source-map', function(err, file) {
assert.equal(file, path.join(__dirname, '../sample.css.map')); assert.equal(file, path.join(__dirname, '../sample.css.map'));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment