source: trip-planner-front/node_modules/pump/test-browser.js@ b738035

Last change on this file since b738035 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.1 KB
Line 
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 reverse
26}
27
28var wsClosed = false
29var rsClosed = false
30var callbackCalled = false
31
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 = true
41 check()
42})
43
44rs.on('end', function () {
45 rsClosed = true
46 check()
47})
48
49var res = pump(rs, toHex(), toHex(), toHex(), ws, function () {
50 callbackCalled = true
51 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)
Note: See TracBrowser for help on using the repository browser.