source: trip-planner-front/node_modules/pump/test-node.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: 992 bytes
RevLine 
[6a3a178]1var pump = require('./index')
2
3var rs = require('fs').createReadStream('/dev/random')
4var ws = require('fs').createWriteStream('/dev/null')
5
6var toHex = function () {
7 var reverse = new (require('stream').Transform)()
8
9 reverse._transform = function (chunk, enc, callback) {
10 reverse.push(chunk.toString('hex'))
11 callback()
12 }
13
14 return reverse
15}
16
17var wsClosed = false
18var rsClosed = false
19var callbackCalled = false
20
21var check = function () {
22 if (wsClosed && rsClosed && callbackCalled) {
23 console.log('test-node.js passes')
24 clearTimeout(timeout)
25 }
26}
27
28ws.on('close', function () {
29 wsClosed = true
30 check()
31})
32
33rs.on('close', function () {
34 rsClosed = true
35 check()
36})
37
38var res = pump(rs, toHex(), toHex(), toHex(), ws, function () {
39 callbackCalled = true
40 check()
41})
42
43if (res !== ws) {
44 throw new Error('should return last stream')
45}
46
47setTimeout(function () {
48 rs.destroy()
49}, 1000)
50
51var timeout = setTimeout(function () {
52 throw new Error('timeout')
53}, 5000)
Note: See TracBrowser for help on using the repository browser.