Code coverage report for spec/readStreamSpec.js

Statements: 23.26% (10 / 43)      Branches: 100% (0 / 0)      Functions: 11.11% (1 / 9)      Lines: 23.26% (10 / 43)      Ignored: none     

All files » spec/ » readStreamSpec.js
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61    1   1 1   1       1                 1           1           1                   1       1                            
/* jshint jasmine: true */
'use strict';
var ReadStream = require('../lib/readStream');
 
describe('readstream spec', function () {
    var readStream;
 
    beforeEach(function () {
        readStream = new ReadStream();
    });
 
    it('should be able to set a buffer', function () {
        readStream.updateBuffer(new Buffer(100));
        expect(readStream._object.length).toBe(100);
        expect(readStream.complete).toBe(false);
        expect(readStream._readableState.ended).toBe(false);
        readStream.setBuffer('abc');
        expect(readStream._object).toEqual('abc');
        expect(readStream.complete).toBe(true);
    });
    it('should be able to read from the stream', function () {
        readStream.updateBuffer(new Buffer(100));
 
        expect(readStream.read(100).length).toEqual(100);
        expect(readStream.read(100)).toEqual(undefined);
    });
    it('should be able to read from a finished stream', function () {
        readStream.setBuffer(new Buffer(100));
 
        expect(readStream.read(100).length).toEqual(100);
        expect(readStream.read(100)).toEqual(null);
    });
    it('should be able to read parts from a finished stream', function () {
        readStream.setBuffer(new Buffer(10000));
 
        expect(readStream.read(450).length).toEqual(450);
        expect(readStream.read(550).length).toEqual(550);
        expect(readStream.read(4000).length).toEqual(4000);
        expect(readStream.read(5000).length).toEqual(5000);
        expect(readStream.read(100)).toEqual(null);
        expect(readStream._readableState.ended).toBe(true);
    });
    it('should be able to read strings', function () {
        readStream.setBuffer('abc');
        expect(readStream.read(10).toString()).toEqual('abc');
    });
    it('after reading the stream should be finished', function (done) {
        readStream.setBuffer(new Buffer(100));
        var endSpy = jasmine.createSpy();
        readStream.on('end', endSpy);
        readStream.read(500);
        readStream.read(500);
        readStream.read(500);
        expect(readStream._readableState.ended).toBe(true);
        setTimeout(function () {
            expect(endSpy).toHaveBeenCalled();
            done();
        }, 30);
    });
});