Skip to content

Commit c8b6d02

Browse files
committed
add tests to cover collection middleware
1 parent 2920c85 commit c8b6d02

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

test/test.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,66 @@ describe('src()', function() {
109109
});
110110
});
111111

112+
it('should emit `app.onStream` and `app.pages.onStream` when using `app.toStream`', function(done) {
113+
var files = [];
114+
var pages = [];
115+
app.onStream(/\.html/, function(file, next) {
116+
files.push(file.path);
117+
next();
118+
});
119+
120+
app.pages.onStream(/\.html/, function(file, next) {
121+
pages.push(file.path);
122+
next();
123+
});
124+
125+
app.toStream('pages')
126+
.on('error', done)
127+
.on('data', function() {})
128+
.on('end', function() {
129+
assert.equal(files.length, 3);
130+
assert.equal(files[0], 'a.html');
131+
assert.equal(files[1], 'b.html');
132+
assert.equal(files[2], 'c.html');
133+
134+
assert.equal(pages.length, 3);
135+
assert.equal(pages[0], 'a.html');
136+
assert.equal(pages[1], 'b.html');
137+
assert.equal(pages[2], 'c.html');
138+
done();
139+
});
140+
});
141+
142+
it('should emit `app.onStream` and `app.pages.onStream` when using `app.pages.toStream`', function(done) {
143+
var files = [];
144+
var pages = [];
145+
app.onStream(/\.html/, function(file, next) {
146+
files.push(file.path);
147+
next();
148+
});
149+
150+
app.pages.onStream(/\.html/, function(file, next) {
151+
pages.push(file.path);
152+
next();
153+
});
154+
155+
app.pages.toStream()
156+
.on('error', done)
157+
.on('data', function() {})
158+
.on('end', function() {
159+
assert.equal(files.length, 3);
160+
assert.equal(files[0], 'a.html');
161+
assert.equal(files[1], 'b.html');
162+
assert.equal(files[2], 'c.html');
163+
164+
assert.equal(pages.length, 3);
165+
assert.equal(pages[0], 'a.html');
166+
assert.equal(pages[1], 'b.html');
167+
assert.equal(pages[2], 'c.html');
168+
done();
169+
});
170+
});
171+
112172
it('should pipe a collection', function(done) {
113173
var files = [];
114174
app.pages.toStream()

0 commit comments

Comments
 (0)