Skip to content

Commit 5084a83

Browse files
committed
update tests to new, simple api
1 parent c68d6ce commit 5084a83

File tree

2 files changed

+49
-33
lines changed

2 files changed

+49
-33
lines changed

test/live-order.js

+29-23
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ var all = []
1010
var h = require('./helper')
1111
var tape = require('tape')
1212

13+
function toKV (d) { return {key: d.key, value: d.value}}
14+
1315
tape('live', function (t) {
1416
return t.end()
1517
var path = '/tmp/pull-level-read-live'
@@ -18,15 +20,16 @@ tape('live', function (t) {
1820

1921
var second = false
2022

21-
h.timestamps(db, 10, function (err, all) {
23+
h.timestamps(db, 11, function (err, all) {
2224

2325
var i = 0
2426
var sync = false
2527
pull(
26-
l.read(db, {live: true, onSync: function () {
27-
console.log('SYNC')
28-
sync = true
29-
}}),
28+
l.read(db, {live: true, values: false}),
29+
pull.filter(function (s) {
30+
if(s.sync) sync = true
31+
else return true
32+
}),
3033
h.exactly(20),
3134
pull.collect(function (err, ary) {
3235
process.nextTick(function () {
@@ -36,9 +39,7 @@ tape('live', function (t) {
3639
t.equal(ary.length, 20)
3740
t.equal(ary.length, all.length)
3841
t.deepEqual(ary, h.sort(ary.slice()))
39-
t.deepEqual(ary.map(function (e) {
40-
return {key: e.key, value: e.value}
41-
}), all)
42+
t.deepEqual(ary.map(toKV), all)
4243
t.ok(sync)
4344
t.end()
4445
})
@@ -47,7 +48,7 @@ tape('live', function (t) {
4748

4849

4950
setTimeout(function () {
50-
h.timestamps(db, 10, function (err, _all) {
51+
h.timestamps(db, 9, function (err, _all) {
5152
second = true
5253
all = all.concat(_all)
5354
console.log('all', all, all.length)
@@ -56,7 +57,6 @@ tape('live', function (t) {
5657
})
5758
})
5859

59-
6060
tape('live2', function (t) {
6161

6262
var path = '/tmp/pull-level-read-live2'
@@ -72,10 +72,11 @@ tape('live2', function (t) {
7272
var i = 0
7373
var sync = false
7474
pull(
75-
l.read(db, {tail: true, keys: false, onSync: function () {
76-
console.log('SYNC')
77-
sync = true
78-
}}),
75+
l.read(db, {live: true}),
76+
pull.filter(function (s) {
77+
if(s.sync) sync = true
78+
else return true
79+
}),
7980
h.exactly(20),
8081
pull.collect(function (err, _ary) {
8182
t.notOk(err)
@@ -102,16 +103,13 @@ tape('live2', function (t) {
102103
t.equal(ary.length, 20)
103104
t.equal(ary.length, all.length)
104105

105-
var values = all.map(function (e) { return e.value })
106-
107-
t.deepEqual(ary, values)
106+
t.deepEqual(ary.map(toKV), all.map(toKV))
108107
t.ok(sync)
109108
t.end()
110109

111110
}
112111
})
113112
})
114-
return
115113

116114
tape('live, sync:true', function (t) {
117115
var path = '/tmp/pull-level-read-live3'
@@ -120,12 +118,12 @@ tape('live, sync:true', function (t) {
120118

121119
var second = false, ary
122120

123-
h.timestamps(db, 10, function (err, all) {
121+
h.timestamps(db, 11, function (err, all) {
124122

125123
var i = 0
126124
var sync = false
127125
pull(
128-
l.read(db, {tail: true, keys: false, sync: true}),
126+
l.read(db, {live: true, sync: true}),
129127
pull.filter(function (data) {
130128
if(data.sync) sync = true
131129
else return true
@@ -140,20 +138,28 @@ tape('live, sync:true', function (t) {
140138

141139

142140
setTimeout(function () {
143-
h.timestamps(db, 10, function (err, _all) {
141+
h.timestamps(db, 9, function (err, _all) {
144142
second = true
145143
all = all.concat(_all)
146144
console.log(ary)
147145
t.equal(ary.length, 20)
148146
t.equal(ary.length, all.length)
149147

150-
var values = all.map(function (e) { return e.value })
148+
// var values = all.map(toKV)
151149

152-
t.deepEqual(ary, values)
150+
t.deepEqual(ary.map(toKV), all)
153151
t.ok(sync)
154152
t.end()
155153
})
156154
}, 100)
157155
})
158156

159157
})
158+
159+
160+
161+
162+
163+
164+
165+

test/read-live.js

+20-10
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,23 @@ require('tape')('live', function (t) {
1818

1919
var n = 3
2020

21-
h.random(db, 10, function (err2, all) {
21+
h.random(db, 11, function (err2, all) {
2222
if(err2) throw err2
2323

2424
pull(
25-
l.read(db, {live: true, onSync: function () {
26-
console.log('sync')
27-
sync = true
28-
}, onAbort: function (end) {
29-
t.ok(end)
30-
if(--n) return
31-
end()
32-
}
25+
l.read(db, {live: true}),
26+
pull.through(function (data) {
27+
console.log("DATA", data)
28+
29+
}, function (end) {
30+
console.log("END", end)
31+
t.ok(end)
32+
if(--n) return
33+
end()
34+
}),
35+
pull.filter(function (d) {
36+
if(d.sync) return !(sync = true)
37+
return true
3338
}),
3439
h.exactly(20, err),
3540
pull.map(function (e) {
@@ -44,7 +49,7 @@ require('tape')('live', function (t) {
4449
})
4550
)
4651

47-
h.random(db, 10, function (err, _all) {
52+
h.random(db, 9, function (err, _all) {
4853
all = h.sort(all.concat(_all))
4954
if(--n) return
5055
end()
@@ -62,3 +67,8 @@ require('tape')('live', function (t) {
6267
}
6368
})
6469
})
70+
71+
72+
73+
74+

0 commit comments

Comments
 (0)