Comparing version 2.0.3 to 2.1.0
@@ -14,3 +14,10 @@ var Readable = require('readable-stream').Readable | ||
return function (_, cb) { | ||
cb(null, list.length ? list.shift() : null) | ||
var err = null | ||
var item = list.length ? list.shift() : null | ||
if (item instanceof Error) { | ||
err = item | ||
item = null | ||
} | ||
cb(err, item) | ||
} | ||
@@ -17,0 +24,0 @@ } |
{ | ||
"name": "from2", | ||
"description": "Convenience wrapper for ReadableStream, with an API lifted from \"from\" and \"through2\"", | ||
"version": "2.0.3", | ||
"version": "2.1.0", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
37
test.js
@@ -87,1 +87,38 @@ var test = require('tape') | ||
}) | ||
test('arrays can emit errors', function (t) { | ||
var input = ['a', 'b', new Error('ooops'), 'c'] | ||
var stream = from(input) | ||
var output = [] | ||
stream.on('data', function (letter) { | ||
output.push(letter.toString()) | ||
}) | ||
stream.on('error', function(e){ | ||
t.deepEqual(['a', 'b'], output) | ||
t.equal('ooops', e.message) | ||
t.end() | ||
}) | ||
stream.on('end', function () { | ||
t.fail('the stream should have errored') | ||
}) | ||
}) | ||
test('obj arrays can emit errors', function (t) { | ||
var input = [{foo:'a'}, {foo:'b'}, new Error('ooops'), {foo:'c'}] | ||
var stream = from.obj(input) | ||
var output = [] | ||
stream.on('data', function (letter) { | ||
output.push(letter) | ||
}) | ||
stream.on('error', function(e){ | ||
t.deepEqual([{foo:'a'}, {foo:'b'}], output) | ||
t.equal('ooops', e.message) | ||
t.end() | ||
}) | ||
stream.on('end', function () { | ||
t.fail('the stream should have errored') | ||
}) | ||
}) | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8968
186