'use strict';

const VideoLib = require('../index');
const MovieParser = VideoLib.MovieParser;
const FragmentListBuilder = VideoLib.FragmentListBuilder;
const FragmentReader = VideoLib.FragmentReader;
const HLSPacketizer = VideoLib.HLSPacketizer;

const fs = require('fs');
const chai = require('chai');
const faker = require('faker');
const expect = chai.expect;

const MOVIE_FILE = './resources/boomstream.mp4';

describe('HLSPacketizer', function () {
    before(function () {
        this.file = fs.openSync(MOVIE_FILE, 'r');
        this.movie = MovieParser.parse(this.file);
    });

    after(function () {
        fs.closeSync(this.file);
    });

    describe('#packetize()', function () {
        describe('when fragment is valid', function () {
            before(function () {
                let fragmentList = FragmentListBuilder.build(this.movie, faker.random.number({min: 3, max: 10}));
                this.fragment = fragmentList.get(faker.random.number({min: 0, max: fragmentList.count() - 1}));
                this.sampleBuffers = FragmentReader.readSamples(this.fragment, this.file);
            });

            it('should return a buffer object', function () {
                return expect(HLSPacketizer.packetize(this.fragment, this.sampleBuffers)).to.be.instanceof(Buffer);
            });

            it('should have right size', function () {
                let size = this.fragment.samples.reduce(function (size, sample) {
                    return size + sample.size;
                }, 0);
                return expect(HLSPacketizer.packetize(this.fragment, this.sampleBuffers).length).to.be.above(size);
            });
        });

        describe('when fragment is not valid', function () {
            it('should throws an error', function () {
                return expect(() => HLSPacketizer.packetize('Some string', this.sampleBuffers)).to.throw('Argument 1 should be instance of Fragment');
            });
        });
    });

});

@@ -365,20 +365,18 @@
 %0Aconst M
-OVIE
+P4
 _FILE = 
@@ -409,274 +409,87 @@
 4';%0A
-%0Adescribe('HLSPacketizer', function () %7B%0A    before(function () %7B%0A        this.file = fs.openSync(MOVIE_FILE, 'r');%0A        this.movie = MovieParser.parse(this.file);%0A    %7D);%0A%0A    after(function () %7B%0A        fs.closeSync(this.file);%0A    %7D);%0A%0A    describe('#p
+const MP4_HEVC_FILE = './resources/boomstream_hevc.mp4';%0A%0Aconst shouldP
 acketize
 ()',
@@ -488,12 +488,10 @@
 tize
-()',
+ =
  fun
@@ -497,28 +497,24 @@
 nction () %7B%0A
-    
     describe
@@ -562,20 +562,16 @@
         
-    
 before(f
@@ -575,36 +575,32 @@
 e(function () %7B%0A
-    
             let 
@@ -701,28 +701,24 @@
             
-    
 this.fragmen
@@ -809,28 +809,24 @@
             
-    
 this.sampleB
@@ -892,37 +892,29 @@
 e);%0A        
- 
-   
 %7D);%0A%0A
-    
         it('
@@ -963,36 +963,32 @@
 ) %7B%0A            
-  
-  
 return expect(HL
@@ -1075,37 +1075,29 @@
 r);%0A        
-    
 %7D);%0A%0A
-    
         it('
@@ -1143,28 +1143,24 @@
             
-    
 let size = t
@@ -1225,28 +1225,24 @@
             
-    
 return size 
@@ -1272,23 +1272,15 @@
     
- 
-   
 %7D, 0);%0A
-    
     
@@ -1391,36 +1391,32 @@
 e);%0A        
-    
 %7D);%0A    
     %7D);%0A%0A   
@@ -1399,37 +1399,29 @@
     %7D);%0A    
-  
-  
 %7D);%0A%0A
-    
     describe
@@ -1469,28 +1469,24 @@
 ) %7B%0A        
-    
 it('should t
@@ -1508,36 +1508,32 @@
 , function () %7B%0A
-    
             retu
@@ -1667,32 +1667,36 @@
 ');%0A        
+%7D);%0A
     %7D);%0A
         %7D);%0A
@@ -1683,27 +1683,877 @@
     %7D);%0A
-        %7D);
+%7D;%0A%0Adescribe('HLSPacketizer', function () %7B%0A%0A    describe('#packetize()', function () %7B%0A%0A        describe('h264/aac', function () %7B%0A            const FILE_NAME = MP4_FILE;%0A%0A            before(function () %7B%0A                this.file = fs.openSync(FILE_NAME, 'r');%0A                this.movie = MovieParser.parse(this.file);%0A            %7D);%0A%0A            after(function () %7B%0A                fs.closeSync(this.file);%0A            %7D);%0A%0A            shouldPacketize();%0A        %7D);%0A%0A        describe('h265/aac', function () %7B%0A            const FILE_NAME = MP4_HEVC_FILE;%0A%0A            before(function () %7B%0A                this.file = fs.openSync(FILE_NAME, 'r');%0A                this.movie = MovieParser.parse(this.file);%0A            %7D);%0A%0A            after(function () %7B%0A                fs.closeSync(this.file);%0A            %7D);%0A%0A            shouldPacketize();%0A        %7D);%0A
 %0A    %7D);

Add more tests