-
Notifications
You must be signed in to change notification settings - Fork 5
/
inmem.js
57 lines (48 loc) · 1.34 KB
/
inmem.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
var d = require('../inmem')
var assert = require('assert')
var server = d().createServer().listen()
var client = d().connect(server)
function logger (name) {
return function (m,n) {
console.log(name+":", m,n)
}
}
var r = client.sub('hello')
//would be nice to just default to {parent: 'master'}
//oh, will probably be adding author too...
//r.on('update', logger('1'))
var a2 = r.commit({a: true})
var a2 = r.commit({a: 2})
function wait (repo, commitish, fn) {
function handler (revs) {
var last = revs[revs.length - 1].id
console.log('at', last)
if(last !== commitish) return
repo.removeListener('update', handler)
fn(revs)
}
repo.on('update', handler)
}
server.once('new', function (r0) {
console.log('new', r0)
wait(r0, a2.id, function () {
assert.deepEqual(r0.checkout(), {a: 2})
console.log('here')
// a second connection to the hello document!
var client2 = d().connect(server)
var r2 = client2.sub('hello')
var n = 1
/*r.once('update', function () {
assert.deepEqual(r.checkout(), {a: 2})
next()
})*/
r2.once('update', function () {
assert.deepEqual(r2.checkout(), {a: 2})
r2.commit({a: 2, b: 3})
r.once('update', function () {
assert.deepEqual(r.checkout(), {a: 2, b: 3})
console.log('PASSED')
})
})
})
})