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
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ module.exports = function (stream, done) {

if (typeof done === 'function') {
deferred.then(function (arr) {
done(null, arr)
process.nextTick(function() {
done(null, arr)
})
}, done)
}

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"devDependencies": {
"bluebird": "^3.1.1",
"istanbul": "0",
"mocha": "^2.3.3"
"mocha": "^2.3.3",
"trycatch": "^1.5.21"
},
"scripts": {
"test": "mocha --reporter spec --bail",
Expand Down
22 changes: 22 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var assert = require('assert')
var stream = require('stream')
var path = require('path')
var fs = require('fs')
var trycatch = require("trycatch")

var toArray = require('..')

Expand Down Expand Up @@ -60,6 +61,27 @@ describe('Stream To Array', function () {
assert.equal(arr.length, 0)
})
})

it('should not swallow errors', function (done) {
var id = {}
trycatch(
function () {
toArray(emptyStream(), function (err, arr) {
if (err)
return done(err)

var err = new Error("foo")
err.id = id
throw err
})
},
function (err) {
assert(err);
assert.equal(err.id, id);
done();
}
)
})
})

describe('as a method', function () {
Expand Down