2 /*global describe:false, it:false */
5 var consume = require('../');
6 var Stream = require('stream');
7 var Readable = Stream.Readable;
8 var Writable = Stream.Writable;
9 var Duplex = Stream.Duplex;
10 var should = require('should');
11 var through = require('through2');
14 describe('stream-consume', function() {
16 it('should cause a Readable stream to complete if it\'s not piped anywhere', function(done) {
17 var rs = new Readable({highWaterMark: 2});
20 rs._read = function() {
29 rs.on("end", function() {
30 a.should.be.above(99);
38 it('should work with Readable streams in objectMode', function(done) {
39 var rs = new Readable({highWaterMark: 2, objectMode: true});
42 rs._read = function() {
51 rs.on("end", function() {
52 a.should.be.above(99);
60 it('should not interfere with a Readable stream that is piped somewhere', function(done) {
61 var rs = new Readable({highWaterMark: 2});
64 rs._read = function() {
74 var ws = new Writable({highWaterMark: 2});
75 ws._write = function(chunk, enc, next) {
76 sizeRead += chunk.length;
80 ws.on("finish", function() {
81 a.should.be.above(99);
83 sizeRead.should.equal(100);
92 it('should not interfere with a Writable stream', function(done) {
93 var rs = new Readable({highWaterMark: 2});
96 rs._read = function() {
106 var ws = new Writable({highWaterMark: 2});
107 ws._write = function(chunk, enc, next) {
108 sizeRead += chunk.length;
112 ws.on("finish", function() {
113 a.should.be.above(99);
114 ended.should.be.true;
115 sizeRead.should.equal(100);
124 it('should handle a Transform stream', function(done) {
125 var rs = new Readable({highWaterMark: 2});
128 rs._read = function() {
139 var ts = through({highWaterMark: 2}, function(chunk, enc, cb) {
140 sizeRead += chunk.length;
148 ts.on("end", function() {
149 a.should.be.above(99);
150 ended.should.be.true;
151 sizeRead.should.equal(100);
152 flushed.should.be.true;
161 it('should handle a classic stream', function(done) {
162 var rs = new Stream();
166 rs.on("end", function() {
167 ended.should.be.true;
173 for (i = 0; i < 100; i++) {