Skip to content

Commit 8cec809

Browse files
committed
more tests, better tests
1 parent 5167080 commit 8cec809

File tree

1 file changed

+93
-6
lines changed

1 file changed

+93
-6
lines changed

test/dest.js

+93-6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ var realMode = function(n) {
3838
return n & parseInt('777', 8);
3939
};
4040

41+
function noop() {}
42+
4143
describe('dest stream', function() {
4244
beforeEach(wipeOut);
4345
afterEach(wipeOut);
@@ -1349,15 +1351,100 @@ describe('dest stream', function() {
13491351
destStream.on('readable', function() {
13501352
var data = destStream.read();
13511353

1352-
if (data == null) {
1353-
// Stream ended
1354-
readables.should.equal(1);
1355-
done();
1356-
} else {
1357-
// New data
1354+
if (data != null) {
13581355
readables++;
13591356
}
13601357
});
1358+
1359+
destStream.on('error', done);
1360+
1361+
destStream.on('finish', function() {
1362+
readables.should.equal(1);
1363+
done();
1364+
});
1365+
});
1366+
1367+
it('should respect data listeners on destination stream', function(done) {
1368+
var srcPath = path.join(__dirname, './fixtures/test.coffee');
1369+
var srcStream = vfs.src(srcPath);
1370+
var destStream = vfs.dest('./out-fixtures/', { cwd: __dirname });
1371+
1372+
srcStream
1373+
.pipe(destStream);
1374+
1375+
var datas = 0;
1376+
destStream.on('data', function() {
1377+
datas++;
1378+
});
1379+
1380+
destStream.on('error', done);
1381+
1382+
destStream.on('finish', function() {
1383+
datas.should.equal(1);
1384+
done();
1385+
});
1386+
});
1387+
1388+
it('sinks the stream if all the readable event handlers are removed', function(done) {
1389+
fs.mkdirSync(path.join(__dirname, './fixtures/highwatermark'));
1390+
for (var idx = 0; idx < 17; idx++) {
1391+
fs.writeFileSync(path.join(__dirname, './fixtures/highwatermark/', 'file' + idx + '.txt'));
1392+
}
1393+
1394+
var srcPath = path.join(__dirname, './fixtures/highwatermark/*.txt');
1395+
var srcStream = vfs.src(srcPath);
1396+
var destStream = vfs.dest('./out-fixtures/', { cwd: __dirname });
1397+
1398+
var fileCount = 0;
1399+
var countFiles = through.obj(function(file, enc, cb) {
1400+
fileCount++;
1401+
1402+
cb(null, file);
1403+
});
1404+
1405+
destStream.on('readable', noop);
1406+
1407+
destStream.once('finish', function() {
1408+
fileCount.should.equal(17);
1409+
done();
1410+
});
1411+
1412+
srcStream.pipe(countFiles).pipe(destStream);
1413+
1414+
destStream.removeListener('readable', noop);
1415+
});
1416+
1417+
it('sinks the stream if all the data event handlers are removed', function(done) {
1418+
fs.mkdirSync(path.join(__dirname, './fixtures/highwatermark'));
1419+
for (var idx = 0; idx < 17; idx++) {
1420+
fs.writeFileSync(path.join(__dirname, './fixtures/highwatermark/', 'file' + idx + '.txt'));
1421+
}
1422+
1423+
var srcPath = path.join(__dirname, './fixtures/highwatermark/*.txt');
1424+
var srcStream = vfs.src(srcPath);
1425+
var destStream = vfs.dest('./out-fixtures/', { cwd: __dirname });
1426+
1427+
var fileCount = 0;
1428+
function onData() {
1429+
fileCount++;
1430+
}
1431+
1432+
var countFiles = through.obj(function(file, enc, cb) {
1433+
onData();
1434+
1435+
cb(null, file);
1436+
});
1437+
1438+
destStream.on('data', onData);
1439+
1440+
destStream.once('finish', function() {
1441+
fileCount.should.equal(17);
1442+
done();
1443+
});
1444+
1445+
srcStream.pipe(countFiles).pipe(destStream);
1446+
1447+
destStream.removeListener('data', onData);
13611448
});
13621449

13631450
it('should pass options to through2', function(done) {

0 commit comments

Comments
 (0)