Skip to content
This repository was archived by the owner on Aug 31, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = function (stream, done) {
}

function onClose() {
resolve()
resolve(arr)
cleanup()
}

Expand Down
26 changes: 26 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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)
})
})
})
})