Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add test for usage of trumpet inside element writable stream #32

Closed
wants to merge 2 commits into from

2 participants

@pragmadash

I am working on stream-based template rendering engine and I've found that some artifacts may appear with steps described below:

  • Create trumpet instance (T1)
  • Select by ID any HTML element using trumpet (T1) and create writable stream for it (W1)
  • Subscribe on 'drain' event of created element writable stream (W1)
  • When W1 'drain' event raises then create another trumpet (T2) instance inside event handler and create writable stream for another HTML element ID (W2) using this new instance of trumpet (T2)
  • Pipe any content or file through T2 to W2 (file.pipe(T2).pipe(W2))
  • And if we pipe to T1 any content with elements which ids were selected we have artifacts on output

Artifacts like character repeats or remove of character etc.
Here is unit test for found issue.
I need this for recursive template rendering, please help.

@substack
Owner

'drain' events were very rarely correctly supported in streams1 and not necessary in streams2, which is what trumpet currently uses internally since 1.6.4. 1.6.4 should fix the issues with character repeats and artifacts.

@substack substack closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 11, 2014
  1. @pragmadash
Commits on Mar 12, 2014
  1. @pragmadash

    Fix test template.

    pragmadash authored
This page is out of date. Refresh to see the latest.
View
44 test/inner.js
@@ -0,0 +1,44 @@
+var path = require('path');
+var fs = require('fs');
+var trumpet = require('../');
+var test = require('tap').test;
+var concat = require('concat-stream');
+var expected = fs
+ .readFileSync(path.join(__dirname, 'inner_expected.html'))
+ .toString();
+var indexPage = fs
+ .createReadStream(path.join(__dirname, 'inner_main.html'));
+var transform = trumpet();
+var elementStream = transform.select('#hello-world')
+ .createWriteStream();
+
+test('Usage of trumpet inside it\'s element write stream', function(t){
+ t.plan(1);
+ elementStream.on('drain', function () {
+ var helloWorldPage = fs
+ .createReadStream(path.join(__dirname, 'inner_block.html'));
+ var innerTransform = trumpet();
+
+ var innerElement = innerTransform
+ .select('#inner-hello-world')
+ .createWriteStream();
+
+ innerElement.on('drain', function () {
+ var innerHelloPage = fs
+ .createReadStream(path.join(__dirname, 'inner_inner_block.html'));
+ innerHelloPage.pipe(innerElement);
+ });
+
+ helloWorldPage
+ .pipe(innerTransform)
+ .pipe(elementStream);
+ });
+
+ indexPage
+ .pipe(transform)
+ .pipe(concat(function(result){
+ var resultString = result.toString();
+ t.deepEqual(resultString, expected);
+ t.end();
+ }));
+});
View
5 test/inner_block.html
@@ -0,0 +1,5 @@
+
+
+ <h1>Hello, world!</h1>
+ <div id="inner-hello-world">
+ </div>
View
14 test/inner_expected.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Trumpet inner usage test</title>
+</head>
+<body>
+ <div id="hello-world">
+ <h1>Hello, world!</h1>
+ <div id="inner-hello-world">
+ <h2>Inner hello!</h2>
+ </div>
+ </div>
+</body>
+</html>
View
2  test/inner_inner_block.html
@@ -0,0 +1,2 @@
+
+ <h2>Inner hello!</h2>
View
10 test/inner_main.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Trumpet inner usage test</title>
+</head>
+<body>
+ <div id="hello-world">
+ </div>
+</body>
+</html>
Something went wrong with that request. Please try again.