diff --git a/index.js b/index.js index cabd718..4301faf 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ module.exports = function (cb) { var ret = ''; - if (!process.stdin.isTTY) { + if (process.stdin.isTTY) { cb(''); return; } @@ -23,7 +23,7 @@ module.exports.buffer = function (cb) { var ret = []; var len = 0; - if (!process.stdin.isTTY) { + if (process.stdin.isTTY) { cb(new Buffer('')); return; } diff --git a/package.json b/package.json index 2c15742..7d15fdd 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "node": ">=0.10.0" }, "scripts": { - "test": "node test.js" + "test": "node test.js && echo unicorns | node test2.js" }, "files": [ "index.js" diff --git a/test.js b/test.js index ee3d5ae..4f65584 100644 --- a/test.js +++ b/test.js @@ -5,6 +5,7 @@ var stdin = require('./'); test('get stdin', function (t) { t.plan(1); + process.stdin.isTTY = false; stdin(function (data) { t.assert(data.trim() === 'unicorns'); @@ -16,6 +17,7 @@ test('get stdin', function (t) { test('get stdin as a buffer', function (t) { t.plan(2); + process.stdin.isTTY = false; stdin.buffer(function (data) { t.assert(bufferEqual(data, new Buffer('unicorns'))); @@ -27,27 +29,20 @@ test('get stdin as a buffer', function (t) { }); test('get empty string when no stdin', function (t) { - var _ = process.stdin.isTTY; - process.stdin.isTTY = false; - t.plan(1); + process.stdin.isTTY = true; stdin(function (data) { t.assert(data === ''); }); - - process.stdin.isTTY = _; }); test('get empty buffer when no stdin', function (t) { - var _ = process.stdin.isTTY; - process.stdin.isTTY = false; - t.plan(1); + process.stdin.isTTY = true; stdin.buffer(function (data) { t.assert(bufferEqual(data, new Buffer(''))); }); - - process.stdin.isTTY = _; }); + diff --git a/test2.js b/test2.js new file mode 100644 index 0000000..c6b63d3 --- /dev/null +++ b/test2.js @@ -0,0 +1,6 @@ +'use strict'; +var stdin = require('./'); + +stdin(function (data) { + process.exit(data ? 0 : 1); +});