CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
test-browser.js67 linesDownload Raw Back to pump
1var stream = require('stream')2var pump = require('./index')3 4var rs = new stream.Readable()5var ws = new stream.Writable()6 7rs._read = function (size) {8  this.push(Buffer(size).fill('abc'))9}10 11ws._write = function (chunk, encoding, cb) {12  setTimeout(function () {13    cb()14  }, 100)15}16 17var toHex = function () {18  var reverse = new (require('stream').Transform)()19 20  reverse._transform = function (chunk, enc, callback) {21    reverse.push(chunk.toString('hex'))22    callback()23  }24 25  return reverse26}27 28var wsClosed = false29var rsClosed = false30var callbackCalled = false31 32var check = function () {33  if (wsClosed && rsClosed && callbackCalled) {34    console.log('test-browser.js passes')35    clearTimeout(timeout)36  }37}38 39ws.on('finish', function () {40  wsClosed = true41  check()42})43 44rs.on('end', function () {45  rsClosed = true46  check()47})48 49var res = pump(rs, toHex(), toHex(), toHex(), ws, function () {50  callbackCalled = true51  check()52})53 54if (res !== ws) {55  throw new Error('should return last stream')56}57 58setTimeout(function () {59  rs.push(null)60  rs.emit('close')61}, 1000)62 63var timeout = setTimeout(function () {64  check()65  throw new Error('timeout')66}, 5000)67