-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
116 lines (109 loc) · 2.11 KB
/
test.js
File metadata and controls
116 lines (109 loc) · 2.11 KB
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
var test = require('tape')
var pull = require('pull-stream')
var debounce = require('.')
function timedSource(data) {
return pull(
pull.values(data),
pull.asyncMap(function(item, cb) {
setTimeout(function() {
cb(null, item[1])
}, item[0]);
})
)
}
test('should ignore frequent updates', function(t) {
pull(
timedSource([
[0, 0],
[250, 1],
[10, 2],
[250, 3],
[2000,4],
[10, 5]
]),
debounce(200),
//pull.through(console.log.bind(console)),
pull.collect(function(end, arr) {
t.notOk(end)
t.deepEqual(arr, [0,2,3,5])
//console.log(arr)
t.end();
})
)
})
test('should ignore even more frequent updates', function(t) {
pull(
timedSource([
[10, 5],
[10, 6],
[10, 7],
[10, 8],
[10, 9],
[10, 10],
[50, 15],
[10, 16],
[10, 17],
[10, 18],
[10, 19],
[10, 20],
]),
debounce(40),
pull.collect((err, arr) => {
t.equal(err, null);
t.deepEqual(arr, [10, 20]);
t.end();
})
);
})
test('should pass through single item', function(t) {
pull(
timedSource([
[0, 0],
]),
debounce(200),
//pull.through(console.log.bind(console)),
pull.collect(function(end, arr) {
t.notOk(end)
t.deepEqual(arr, [0])
//console.log(arr)
t.end();
})
)
})
test('should pass through single item after timeout', function(t) {
var items = []
var start = Date.now();
pull(
timedSource([
[0, 0],
[2000, 1]
]),
debounce(200),
pull.through(function(item) {
//console.log(item)
items.push(item)
}),
pull.drain()
)
setTimeout(function() {
t.equal(items.length, 1)
t.end()
}, 1000)
})
test('should pass through late last item', function(t) {
pull(
timedSource([
[0, 0],
[199, 1],
[2000,2]
]),
debounce(200),
//pull.through(console.log.bind(console)),
pull.collect(function(end, arr) {
t.notOk(end)
t.deepEqual(arr, [1,2])
//console.log(arr)
t.end();
})
)
})