react / wstein / node_modules / browserify / node_modules / labeled-stream-splicer / node_modules / stream-splicer / test / push.js
80540 viewsvar pipeline = require('../');1var through = require('through2');2var split = require('split');3var concat = require('concat-stream');4var test = require('tape');56test('push', function (t) {7var expected = {};8expected.first = [ 333, 444, 555, 666, 777 ];9expected.second = [ 6.66, 7.77 ];10expected.output = [ 3.33, 4.44, 5.55, 3, 2 ];1112t.plan(5 + 2 + 5 + 3);1314var a = split();15var b = through.obj(function (row, enc, next) {16this.push(JSON.parse(row));17next();18});19var c = through.obj(function (row, enc, next) { this.push(row.x); next() });20var d = through.obj(function (x, enc, next) { this.push(x * 111); next() });2122var first = through.obj(function (row, enc, next) {23if (expected.first.length === 2) {24t.equal(p.length, 5);25p.push(second);26t.equal(p.length, 6);27}2829var ex = expected.first.shift();30t.deepEqual(row, ex);3132this.push(row / 100);33next();34});35var second = through.obj(function (row, enc, next) {36var ex = expected.second.shift();37t.deepEqual(row, ex);38this.push(Math.floor(10 - row));39next();40});4142var p = pipeline.obj([ a, b, c, d, first ]);43t.equal(p.length, 5);4445p.pipe(through.obj(function (row, enc, next) {46var ex = expected.output.shift();47t.deepEqual(row, ex);48next();49}));5051p.write('{"x":3}\n');52p.write('{"x":4}\n');53p.write('{"x":5}\n');54p.write('{"x":6}\n');55p.write('{"x":7}');56p.end();57});585960