Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
99 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
var test = require('tap').test; | ||
var trumpet = require('../'); | ||
var fs = require('fs'); | ||
var BufferedStream = require('bufferedstream'); | ||
|
||
test('compose with streams', function (t) { | ||
t.plan(1); | ||
var html = fs.readFileSync(__dirname + '/compose_target.html', 'utf8'); | ||
|
||
var tr = trumpet(); | ||
fs.createReadStream(__dirname + '/compose.html').pipe(tr); | ||
|
||
var tr2 = trumpet(); | ||
fs.createReadStream(__dirname + '/partial.html').pipe(tr2); | ||
|
||
var tr3 = trumpet(); | ||
fs.createReadStream(__dirname + '/partial.html').pipe(tr3); | ||
tr3.select('.b span', function(node) { | ||
node.update(function(html) { | ||
return html.toUpperCase(); | ||
}); | ||
}); | ||
|
||
var stream = new BufferedStream(); | ||
stream.end('<b>NOTHING TO SEE HERE</b>'); | ||
|
||
var stream2 = new BufferedStream(); | ||
stream2.end('<blink>TERRIBLE</blink>'); | ||
|
||
tr.map({ | ||
'.b span': tr2, | ||
'.c': tr3, | ||
'.d': { remove: true }, | ||
'.e': { remove: true }, | ||
'.f': { replace: stream }, | ||
'.g': { replace: stream2} | ||
}); | ||
|
||
var data = ''; | ||
tr.on('data', function (buf) { data += buf }); | ||
|
||
tr.on('end', function () { | ||
t.equal(data, html); | ||
}); | ||
}); |