-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.js
118 lines (105 loc) · 2.87 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
var test = require('tape');
var spawn = require('child_process').spawn;
var tmpdir = require('os').tmpdir;
var fs = require('fs');
test('bin stdin pass through', function(t){
var ps = spawn(__dirname + '/bin/pv.js');
ps.on('error', t.error.bind(t));
ps.stdout.on('data', function(chunk){
t.equal(chunk.toString(), 'hey');
t.end();
});
ps.stdin.end('hey');
});
test('bin stdarg read', function(t){
var tmp = tmpdir() + '/pv' + Math.random();
fs.writeFileSync(tmp, 'hey');
var ps = spawn(__dirname + '/bin/pv.js', [tmp]);
ps.on('error', t.error.bind(t));
ps.stdout.on('data', function(chunk){
t.equal(chunk.toString(), 'hey');
t.end();
});
});
test('bin volume', function(t){
var ps = spawn(__dirname + '/bin/pv.js');
ps.on('error', t.error.bind(t));
ps.stderr.once('data', function(chunk){
ps.stdin.end();
t.ok(/3B/.test(chunk.toString()));
t.end();
});
ps.stdin.write('hey');
});
test('bin time', function(t){
var ps = spawn(__dirname + '/bin/pv.js');
ps.on('error', t.error.bind(t));
ps.stderr.once('data', function(chunk){
ps.stdin.end();
t.ok(/00:00:00/.test(chunk.toString()));
t.end();
});
ps.stdin.write('hey');
});
test('bin throughput', function(t){
var ps = spawn(__dirname + '/bin/pv.js');
ps.on('error', t.error.bind(t));
ps.stderr.once('data', function(chunk){
ps.stdin.end();
t.ok(/\[3B\/s\]/.test(chunk.toString()));
t.end();
});
ps.stdin.write('hey');
});
test('bin name', function(t){
var ps = spawn(__dirname + '/bin/pv.js', ['-N', 'test']);
ps.on('error', t.error.bind(t));
ps.stderr.once('data', function(chunk){
ps.stdin.end();
t.ok(/test:/.test(chunk.toString()));
t.end();
});
ps.stdin.write('hey');
});
test('bin size arg', function(t){
var ps = spawn(__dirname + '/bin/pv.js', ['-s', '30']);
ps.on('error', t.error.bind(t));
ps.stderr.once('data', function(chunk){
ps.stdin.end();
t.ok(/10%/.test(chunk.toString()));
t.end();
});
ps.stdin.write('hey');
});
test('bin argv size', function(t){
var tmp = tmpdir() + '/pv' + Math.random();
fs.writeFileSync(tmp, 'hey');
var ps = spawn(__dirname + '/bin/pv.js', [tmp]);
ps.on('error', t.error.bind(t));
ps.stderr.once('data', function(chunk){
ps.stdin.end();
t.ok(/100%/.test(chunk.toString()));
t.end();
});
ps.stdin.write('hey');
});
test('bin eta', function(t){
var ps = spawn(__dirname + '/bin/pv.js', ['-s', '30']);
ps.on('error', t.error.bind(t));
ps.stderr.once('data', function(chunk){
ps.stdin.end();
t.ok(/ETA 00:00:09/.test(chunk.toString()));
t.end();
});
ps.stdin.write('hey');
});
test('bin no newline', function(t){
var ps = spawn(__dirname + '/bin/pv.js');
ps.on('error', t.error.bind(t));
ps.stderr.once('data', function(chunk){
ps.stdin.end();
t.notOk(/\n/.test(chunk.toString()));
t.end();
});
ps.stdin.write('hey');
});