/
Store.js
68 lines (59 loc) · 1.9 KB
/
Store.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
var Jog = require('../../')
, fs = require('fs');
module.exports = function(store){
describe('#stream()', function(){
it('should emit "data" and "end" events', function(done){
var log = new Jog(store);
log.write('info', 'compiling video', { vid: 'abc' });
log.write('info', 'uploading video', { vid: 'abc' });
var stream = log.stream();
var lines = [];
stream.on('data', function(line){
lines.push(line);
}).on('end', function(){
lines[0].should.have.property('timestamp');
delete lines[0].timestamp;
delete lines[1].timestamp;
lines[0].should.eql({ vid: 'abc', level: 'info', type: 'compiling video' });
lines[1].should.eql({ vid: 'abc', level: 'info', type: 'uploading video' });
done();
});
})
describe('when "end" is false', function(){
it('should remain open', function(done){
var log = new Jog(store)
, stream = log.stream({ end: false, interval: 100 })
, n = 0;
var id = setInterval(function(){
log.write('info', 'compiling video', { vid: ++n });
}, 2);
stream.on('data', function(line){
if (line.vid == 20) {
clearInterval(id);
done();
}
}).on('end', function(){
done(new Error('called end'));
});
})
})
})
describe('#clear(fn)', function(){
it('should clear the data', function(done){
var log = new Jog(store);
log.write('info', 'compiling video', { vid: 'abc' });
log.write('info', 'uploading video', { vid: 'abc' });
log.clear(function(err){
if (err) return done(err);
var stream = log.stream();
var lines = [];
stream.on('data', function(line){
lines.push(line);
}).on('end', function(){
lines.should.have.length(0);
done();
});
})
})
})
}