6a7f0679 by David LaPalomento

Add method to test m3u8s directly against expected JSON output

There are a ton of tests in m3u8_test.js currently and it's getting a bit difficult to manage. Instead of hand-writing checks for each property of the parsed output, automatically convert manifests to javscript strings during the build process and then compare the parse of that string against a JSON file with the same name.
1 parent 69be9f80
'use strict';
var basename = require('path').basename;
module.exports = function(grunt) {
// Project configuration.
......@@ -12,7 +14,7 @@ module.exports = function(grunt) {
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n',
// Task configuration.
clean: {
files: ['build', 'dist']
files: ['build', 'dist', 'tmp']
},
concat: {
options: {
......@@ -93,11 +95,56 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('manifests-to-js', 'Wrap the test fixtures and output' +
' so they can be loaded in a browser',
function() {
var
jsManifests = 'window.manifests = {\n',
jsExpected = 'window.expected = {\n';
grunt.file.recurse('test/manifest/',
function(abspath, root, sub, filename) {
if ((/\.m3u8$/).test(abspath)) {
// translate this manifest
jsManifests += ' \'' + basename(filename, '.m3u8') + '\': ' +
grunt.file.read(abspath)
.split('\n')
// quote and concatenate
.map(function(line) {
return ' \'' + line + '\\n\' +\n';
}).join('')
// strip leading spaces and the trailing '+'
.slice(4, -3);
jsManifests += ',\n';
}
if ((/\.json$/).test(abspath)) {
// append the JSON
jsExpected += ' "' + basename(filename, '.json') + '": ' +
grunt.file.read(abspath) + ',\n';
}
});
// clean up and close the objects
jsManifests = jsManifests.slice(0, -2);
jsManifests += '\n};\n';
jsExpected = jsExpected.slice(0, -2);
jsExpected += '\n};\n';
// write out the manifests
grunt.file.write('tmp/manifests.js', jsManifests);
grunt.file.write('tmp/expected.js', jsExpected);
});
// Default task.
grunt.registerTask('default',
['jshint',
['clean',
'jshint',
'manifests-to-js',
'qunit',
'clean',
'concat',
'uglify']);
......
......@@ -1126,4 +1126,19 @@
'the byterange offset was defaulted');
});
module('m3u8s');
test('parses the example manifests as expected', function() {
var key;
for (key in window.manifests) {
if (window.expected[key]) {
parser = new Parser();
parser.push(window.manifests[key]);
deepEqual(parser.manifest,
window.expected[key],
key + '.m3u8 was parsed correctly');
}
}
});
})(window, window.console);
......
{
"allowCache": true,
"targetDuration": 10,
"mediaSequence": 0,
"playlistType": "VOD",
"segments": [{
"duration": 10,
"byterange": {
"length": 522828,
"offset": 0
},
"uri": "hls_450k_video.ts"
}, {
"duration": 10,
"byterange": {
"length": 587500,
"offset": 522828
},
"uri": "hls_450k_video.ts"
}, {
"duration": 10,
"byterange": {
"length": 713084,
"offset": 1110328
},
"uri": "hls_450k_video.ts"
}, {
"duration": 10,
"byterange": {
"length": 476580,
"offset": 1823412
},
"uri": "hls_450k_video.ts"
}, {
"duration": 10,
"byterange": {
"length": 535612,
"offset": 2299992
},
"uri": "hls_450k_video.ts"
}, {
"duration": 10,
"byterange": {
"length": 207176,
"offset": 2835604
},
"uri": "hls_450k_video.ts"
}, {
"duration": 10,
"byterange": {
"length": 455900,
"offset": 3042780
},
"uri": "hls_450k_video.ts"
}, {
"duration": 10,
"byterange": {
"length": 657248,
"offset": 3498680
},
"uri": "hls_450k_video.ts"
}, {
"duration": 10,
"byterange": {
"length": 571708,
"offset": 4155928
},
"uri": "hls_450k_video.ts"
}, {
"duration": 10,
"byterange": {
"length": 485040,
"offset": 4727636
},
"uri": "hls_450k_video.ts"
}, {
"duration": 10,
"byterange": {
"length": 709136,
"offset": 5212676
},
"uri": "hls_450k_video.ts"
}, {
"duration": 10,
"byterange": {
"length": 730004,
"offset": 5921812
},
"uri": "hls_450k_video.ts"
}, {
"duration": 10,
"byterange": {
"length": 456276,
"offset": 6651816
},
"uri": "hls_450k_video.ts"
}, {
"duration": 10,
"byterange": {
"length": 468684,
"offset": 7108092
},
"uri": "hls_450k_video.ts"
}, {
"duration": 10,
"byterange": {
"length": 444996,
"offset": 7576776
},
"uri": "hls_450k_video.ts"
}, {
"duration": 10,
"byterange": {
"length": 331444,
"offset": 8021772
},
"uri": "hls_450k_video.ts"
}, {
"duration": 1.4167,
"byterange": {
"length": 44556,
"offset": 8353216
},
"uri": "hls_450k_video.ts"
}]
}
......@@ -34,11 +34,13 @@
<script src="manifest/playlist_allow_cache_template.js"></script>
<script src="manifest/playlist_byte_range_template.js"></script>
<script src="../tmp/manifests.js"></script>
<script src="../tmp/expected.js"></script>
<!-- M3U8 -->
<!-- SEGMENT -->
<script src="tsSegment-bc.js"></script>
<script src="../src/segment-controller.js"></script>
<script src="../src/bin-utils.js"></script>
<!-- Test cases -->
......