Commit 5c05acfc by Adeel Mujahid

Merge pull request #486 from pluma/nontty

Don't rely on isTTY for stdin/stdout
parents 5f275e71 99c2d253
......@@ -134,7 +134,7 @@ module.exports = function(args) {
options.src = input[0] || null;
options.dest = options.output || input[1] || null;
if (!options.dest && (process.stdout.isTTY || process.env.isTTY)) {
if (!options.dest && !options.stdout) {
var suffix = '.css';
if (/\.css$/.test(options.src)) {
suffix = '';
......@@ -142,18 +142,17 @@ module.exports = function(args) {
options.dest = path.join(cwd, path.basename(options.src, '.scss') + suffix);
}
if (process.stdin.isTTY || process.env.isTTY) {
if (!input.length) {
if (options.src) {
run(options, emitter);
} else if (!input.length && (process.stdin.isTTY || process.env.isTTY)) {
console.error([
'Provide a sass file to render',
'',
'Example',
' Example',
' node-sass --output-style compressed foobar.scss foobar.css',
' cat foobar.scss | node-sass --output-style compressed > foobar.css'
].join('\n'));
process.exit(1);
}
run(options, emitter);
} else {
stdin(function(data) {
options.data = data;
......
......@@ -120,6 +120,24 @@ describe('cli', function() {
});
});
it('should compile sample.scss as sample.css without isTTY', function(done) {
this.timeout(6000);
var env = assign(process.env, { isTTY: '' });
var resultPath = path.join(__dirname, 'sample.css');
exec('node ' + cliPath + ' ' + sampleFilename, {
cwd: __dirname,
env: env
}, function(err) {
assert.equal(err, null);
fs.exists(resultPath, function(exists) {
assert(exists);
fs.unlink(resultPath, done);
});
});
});
it('should compile sample.scss to ../out.css', function(done) {
this.timeout(6000);
var env = assign(process.env, { isTTY: true });
......@@ -204,10 +222,47 @@ describe('cli', function() {
emitter.on('error', done);
emitter.on('done', function() {
fs.exists(sampleCssOutputPath, function(exists) {
if (exists) {fs.unlinkSync(sampleCssOutputPath);}
assert(!exists);
done();
});
});
});
it('should write to stdout with the --stdout option without isTTY', function(done) {
this.timeout(6000);
var env = assign(process.env, { isTTY: '' });
exec('node ' + cliPath + ' --stdout ' + sampleScssPath, {
cwd: __dirname,
env: env
}, function(err, stdout) {
if (err) {
done(err);
} else {
assert.equal(stdout.replace(/[\n\r]$/, ''), expectedSampleNoComments);
done();
}
});
});
it('should not write to disk with the --stdout option without isTTY', function(done) {
this.timeout(6000);
var env = assign(process.env, { isTTY: '' });
exec('node ' + cliPath + ' --stdout ' + sampleScssPath, {
cwd: __dirname,
env: env
}, function(err) {
if (err) {
done(err);
} else {
fs.exists(sampleCssOutputPath, function(exists) {
if (exists) {fs.unlinkSync(sampleCssOutputPath);}
assert(!exists);
done();
});
}
});
});
......
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