-
Notifications
You must be signed in to change notification settings - Fork 66
/
update_streaming.js
62 lines (51 loc) · 1.6 KB
/
update_streaming.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
var test = require('tap').test;
var trumpet = require('../');
var fs = require('fs');
var BufferedStream = require('bufferedstream');
test('update', function (t) {
t.plan(2);
var html = fs.readFileSync(__dirname + '/update_target.html', 'utf8');
var tr = trumpet();
fs.createReadStream(__dirname + '/update.html').pipe(tr);
var spans = [ 'tacos', 'y', 'burritos' ];
tr.select('.b span', function (node) {
node.update(function (html) {
var stream = new BufferedStream();
stream.end(html.toUpperCase());
return stream;
});
});
tr.select('.c', function (node) {
node.update(function() {
var stream = new BufferedStream();
stream.end('---');
return stream;
});
});
tr.select('.d', function (node) {
node.remove();
});
tr.select('.e', function (node) {
node.remove();
});
tr.select('.f', function (node) {
node.replace(function() {
var stream = new BufferedStream();
stream.end('<b>NOTHING TO SEE HERE</b>');
return stream;
});
});
tr.select('.g', function (node) {
node.replace(function (html) {
t.equal(html, '<div class="g">EVERYTHING IS TERRIBLE</div>');
var stream = new BufferedStream();
stream.end('<blink>TERRIBLE</blink>');
return stream;
});
});
var data = '';
tr.on('data', function (buf) { data += buf });
tr.on('end', function () {
t.equal(data, html);
});
});