diff --git a/index.js b/index.js index 329a324..1affd3a 100644 --- a/index.js +++ b/index.js @@ -35,7 +35,7 @@ module.exports = function (stream, done) { } function onClose() { - resolve() + resolve(arr) cleanup() } diff --git a/test/index.js b/test/index.js index d476c0a..05f9e6c 100644 --- a/test/index.js +++ b/test/index.js @@ -16,6 +16,16 @@ function emptyStream() { return s } +function closedStream() { + var s = new stream.Readable(); + s._read = function () { + } + process.nextTick(function () { + s.emit('close') + }) + return s +} + describe('Stream To Array', function () { describe('as a function', function () { it('should work', function (done) { @@ -43,6 +53,13 @@ describe('Stream To Array', function () { assert.equal(arr.length, 0) }) }) + + it('should work as a promise with chucky', function () { + return toArray(closedStream()).then(function (arr) { + assert.ok(Array.isArray(arr)) + assert.equal(arr.length, 0) + }) + }) }) describe('as a method', function () { @@ -77,5 +94,14 @@ describe('Stream To Array', function () { assert.equal(arr.length, 0) }) }) + + it('should work as a promise with chucky', function () { + var stream = closedStream() + stream.toArray = toArray + return stream.toArray().then(function (arr) { + assert.ok(Array.isArray(arr)) + assert.equal(arr.length, 0) + }) + }) }) })