2 var test = require('tape')
3 var spec = require('stream-spec')
4 var through = require('../')
7 I'm using these two functions, and not streams and pipe
8 so there is less to break. if this test fails it must be
9 the implementation of _through_
12 function write(array, stream) {
16 if(stream.write(array.shift()) === false)
17 return stream.once('drain', next)
25 function read(stream, callback) {
27 stream.on('data', function (data) {
30 stream.once('end', function () {
31 callback(null, actual)
33 stream.once('error', function (err) {
38 test('simple defaults', function(assert) {
43 while(l--) expected.push(l * Math.random())
46 var s = spec(t).through().pausable()
48 read(t, function (err, actual) {
50 assert.deepEqual(actual, expected)
54 t.on('close', s.validate)
59 test('simple functions', function(assert) {
64 while(l--) expected.push(l * Math.random())
66 var t = through(function (data) {
67 this.emit('data', data*2)
69 var s = spec(t).through().pausable()
72 read(t, function (err, actual) {
74 assert.deepEqual(actual, expected.map(function (data) {
80 t.on('close', s.validate)
85 test('pauses', function(assert) {
90 while(l--) expected.push(l) //Math.random())
98 t.on('data', function () {
99 if(Math.random() > 0.1) return
101 process.nextTick(function () {
106 read(t, function (err, actual) {
108 assert.deepEqual(actual, expected)
111 t.on('close', function () {
119 test('does not soft-end on `undefined`', function(assert) {
120 var stream = through()
123 stream.on('data', function (data) {
127 stream.write(undefined)
128 stream.write(undefined)
130 assert.equal(count, 2)