diff --git a/index.js b/index.js index 0319636..0cbbcca 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,16 @@ var PauseStream = require('pause-stream'); -module.exports = function() { - var streams = Array.prototype.slice.call(arguments), - pending = streams.length; +module.exports = function(input) { + var streams; + if(input instanceof Array){ + streams = input; + } + else { + streams = arguments; + } + streams = Array.prototype.slice.call(streams); + + var pending = streams.length; var stream = new PauseStream(); diff --git a/test/stream-series-test.js b/test/stream-series-test.js index 9aa049d..149b71f 100644 --- a/test/stream-series-test.js +++ b/test/stream-series-test.js @@ -3,6 +3,33 @@ var expect = require('expect.js'), series = require('../'), es = require('event-stream'); +describe('streams-array', function(){ + it('Accepts streams as arguments or as an array', function(){ + var streamNames = ['one', 'two', 'three', 'four', 'five'], + streams = [], + expected = []; + + streamNames.map(function(e, i){ + var stream = es.through(function write(data){ + data.name = e; + this.emit('data', data); + }); + streams.push(stream); + expected.push({val: i, name: e}); + }); + + var writer = es.through(function(data) { + expect(data).to.be.eql(expected[data.val]); + }); + + series(streams).pipe(writer); + + for(var i = 0; i < streamNames.length; i++){ + streams[i].end({val:i}); + } + }); +}); + describe('stream-waterfall', function() { it('waits for one stream to end before calling the next', function(done) { var firstStream = es.through(function(data) {