react / wstein / node_modules / browserify / node_modules / labeled-stream-splicer / node_modules / stream-splicer / test / pop.js
80540 viewsvar pipeline = require('../');1var through = require('through2');2var split = require('split');3var concat = require('concat-stream');4var test = require('tape');56test('pop', function (t) {7var expected = {};8expected.replacer = [ '333', '444' ];910t.plan(3);1112var a = split();13var b = through.obj(function (row, enc, next) {14this.push(JSON.parse(row));15next();16});17var c = through.obj(function (row, enc, next) {18this.push(row.x);19next();20});21var d = through.obj(function (x, enc, next) {22this.push(String(x * 111));23next();24});25var replacer = through(function (buf, enc, next) {26var ex = expected.replacer.shift();27t.equal(buf.toString(), ex);28this.push(buf.toString('hex') + '\n');29if (expected.replacer.length === 0) {30stream.pop();31}32next();33});3435var stream = pipeline([ a, b, c, d, replacer ]);36stream.pipe(concat(function (body) {37t.deepEqual(body.toString(), '333333\n343434\n555666');38}));3940stream.write('{"x":3}\n');41stream.write('{"x":4}\n');42stream.write('{"x":5}\n');43stream.write('{"x":6}');44stream.end();45});464748