-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
44 lines (35 loc) · 1.34 KB
/
test.js
File metadata and controls
44 lines (35 loc) · 1.34 KB
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
var expect = require('chai').expect;
var stream = require('stream');
var RandStream = require('randstream');
var concat = require('concat-stream');
var TruncateStream = require('./truncate-stream');
describe('truncate-stream', function() {
it('should truncate the input when enough is provided in the first chunk', function (done) {
var source = new RandStream();
var truncate = new TruncateStream({maxBytes: 1024});
source.pipe(truncate).pipe(concat(function(data) {
expect(data).to.have.lengthOf(1024);
done();
}));
});
it('should truncate the input with multi-chunk streams', function (done) {
var source = new RandStream();
var truncate = new TruncateStream({maxBytes: 100000});
source.pipe(truncate).pipe(concat(function(data) {
expect(data).to.have.lengthOf(100000);
done();
}));
});
it('should not truncate a stream that was smaller than the maxBytes', function (done) {
var source = new stream.Readable();
source._read = function () {
this.push(typeof(Buffer.alloc) == 'function' ? Buffer.alloc(100) : new Buffer(100)); // support for node 6 Buffer.alloc method
this.push(null);
};
var truncate = new TruncateStream({maxBytes: 1024});
source.pipe(truncate).pipe(concat(function (data) {
expect(data).to.have.lengthOf(100);
done();
}));
});
});