1 var assert = require('assert');
2 var pipe = require('..');
3 var Stream = require('stream');
5 describe('pipe(a)', function(){
6 it('should return a', function(){
7 var readable = Readable();
8 var stream = pipe(readable);
9 assert.equal(stream, readable);
13 describe('pipe(a, b, c)', function(){
14 it('should pipe internally', function(done){
15 pipe(Readable(), Transform(), Writable(done));
18 it('should be writable', function(done){
19 var stream = pipe(Transform(), Writable(done));
20 assert(stream.writable);
21 Readable().pipe(stream);
24 it('should be readable', function(done){
25 var stream = pipe(Readable(), Transform());
26 assert(stream.readable);
27 stream.pipe(Writable(done));
30 it('should be readable and writable', function(done){
31 var stream = pipe(Transform(), Transform());
32 assert(stream.readable);
33 assert(stream.writable);
36 .pipe(Writable(done));
39 describe('errors', function(){
40 it('should reemit', function(done){
44 var stream = pipe(a, b, c);
48 stream.on('error', function(_err){
50 assert.equal(_err, err);
60 it('should not reemit endlessly', function(done){
65 var stream = pipe(a, b, c);
69 stream.on('error', function(_err){
71 assert.equal(_err, err);
83 describe('pipe(a, b, c, fn)', function(){
84 it('should call on finish', function(done){
88 var c = Writable(function(){
92 pipe(a, b, c, function(err){
99 it('should call with error once', function(done){
105 pipe(a, b, c, function(err){
110 a.emit('error', err);
111 b.emit('error', err);
112 c.emit('error', err);
117 var readable = new Stream.Readable({ objectMode: true });
118 readable._read = function(){
125 function Transform(){
126 var transform = new Stream.Transform({ objectMode: true });
127 transform._transform = function(chunk, _, done){
128 done(null, chunk.toUpperCase());
133 function Writable(cb){
134 var writable = new Stream.Writable({ objectMode: true });
135 writable._write = function(chunk, _, done){
136 assert.equal(chunk, 'A');