Skip to content

Commit

Permalink
test: add more tests for vtt (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
forbesjo authored Dec 12, 2017
1 parent 96fc406 commit 4068790
Show file tree
Hide file tree
Showing 2 changed files with 288 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/toM3u8.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const formatAudioPlaylist = ({ attributes, segments }) => {
};

export const formatVttPlaylist = ({ attributes, segments }) => {
if (segments === undefined) {
if (typeof segments === 'undefined') {
segments = [{
uri: attributes.url,
timeline: attributes.periodIndex,
Expand Down
292 changes: 287 additions & 5 deletions test/toM3u8.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ QUnit.test('playlists', function(assert) {
periodIndex: 1,
mimeType: 'text/vtt',
url: 'https://www.example.com/vtt'
},
segments: []
}
}, {
attributes: {
sourceDuration: 100,
Expand All @@ -54,8 +53,7 @@ QUnit.test('playlists', function(assert) {
periodIndex: 1,
mimeType: 'text/vtt',
url: 'https://www.example.com/vtt'
},
segments: []
}
}];

const expected = {
Expand Down Expand Up @@ -102,7 +100,12 @@ QUnit.test('playlists', function(assert) {
},
endList: true,
resolvedUri: 'https://www.example.com/vtt',
segments: [],
segments: [{
duration: 100,
resolvedUri: 'https://www.example.com/vtt',
timeline: 1,
uri: 'https://www.example.com/vtt'
}],
timeline: 1,
uri: ''
}],
Expand Down Expand Up @@ -138,6 +141,285 @@ QUnit.test('playlists', function(assert) {
assert.deepEqual(toM3u8(input), expected);
});

QUnit.test('playlists with segments', function(assert) {
const input = [{
attributes: {
id: '1',
codecs: 'foo;bar',
sourceDuration: 100,
bandwidth: '20000',
periodIndex: 1,
mimeType: 'audio/mp4'
},
segments: [{
uri: '',
timeline: 1,
duration: 2,
resolvedUri: '',
map: {
uri: '',
resolvedUri: ''
}
}, {
uri: '',
timeline: 1,
duration: 2,
resolvedUri: '',
map: {
uri: '',
resolvedUri: ''
}
}]
}, {
attributes: {
id: '2',
codecs: 'foo;bar',
sourceDuration: 100,
bandwidth: '10000',
periodIndex: 1,
mimeType: 'audio/mp4'
},
segments: [{
uri: '',
timeline: 1,
duration: 2,
resolvedUri: '',
map: {
uri: '',
resolvedUri: ''
}
}, {
uri: '',
timeline: 1,
duration: 2,
resolvedUri: '',
map: {
uri: '',
resolvedUri: ''
}
}]
}, {
attributes: {
sourceDuration: 100,
id: '1',
width: '800',
height: '600',
codecs: 'foo;bar',
bandwidth: '10000',
periodIndex: 1,
mimeType: 'video/mp4'
},
segments: [{
uri: '',
timeline: 1,
duration: 2,
resolvedUri: '',
map: {
uri: '',
resolvedUri: ''
}
}, {
uri: '',
timeline: 1,
duration: 2,
resolvedUri: '',
map: {
uri: '',
resolvedUri: ''
}
}]
}, {
attributes: {
sourceDuration: 100,
id: '1',
bandwidth: '20000',
periodIndex: 1,
mimeType: 'text/vtt',
url: 'https://www.example.com/vtt'
},
segments: [{
uri: '',
timeline: 1,
duration: 2,
resolvedUri: '',
map: {
uri: '',
resolvedUri: ''
}
}, {
uri: '',
timeline: 1,
duration: 2,
resolvedUri: '',
map: {
uri: '',
resolvedUri: ''
}
}]
}, {
attributes: {
sourceDuration: 100,
id: '1',
bandwidth: '10000',
periodIndex: 1,
mimeType: 'text/vtt',
url: 'https://www.example.com/vtt'
},
segments: [{
uri: '',
timeline: 1,
duration: 2,
resolvedUri: '',
map: {
uri: '',
resolvedUri: ''
}
}, {
uri: '',
timeline: 1,
duration: 2,
resolvedUri: '',
map: {
uri: '',
resolvedUri: ''
}
}]
}];

const expected = {
allowCache: true,
discontinuityStarts: [],
duration: 100,
endList: true,
mediaGroups: {
AUDIO: {
audio: {
main: {
autoselect: true,
default: true,
language: '',
playlists: [{
attributes: {
BANDWIDTH: 20000,
CODECS: 'foo;bar',
NAME: '1',
['PROGRAM-ID']: 1
},
endList: true,
resolvedUri: '',
segments: [{
uri: '',
timeline: 1,
duration: 2,
resolvedUri: '',
map: {
uri: '',
resolvedUri: ''
}
}, {
uri: '',
timeline: 1,
duration: 2,
resolvedUri: '',
map: {
uri: '',
resolvedUri: ''
}
}],
timeline: 1,
uri: ''
}],
uri: ''
}
}
},
['CLOSED-CAPTIONS']: {},
SUBTITLES: {
subs: {
text: {
autoselect: false,
default: false,
language: 'text',
playlists: [{
attributes: {
BANDWIDTH: 20000,
NAME: '1',
['PROGRAM-ID']: 1
},
endList: true,
resolvedUri: 'https://www.example.com/vtt',
segments: [{
uri: '',
timeline: 1,
duration: 2,
resolvedUri: '',
map: {
uri: '',
resolvedUri: ''
}
}, {
uri: '',
timeline: 1,
duration: 2,
resolvedUri: '',
map: {
uri: '',
resolvedUri: ''
}
}],
timeline: 1,
uri: ''
}],
uri: ''
}
}
},
VIDEO: {}
},
playlists: [{
attributes: {
AUDIO: 'audio',
SUBTITLES: 'subs',
BANDWIDTH: 10000,
CODECS: 'foo;bar',
NAME: '1',
['PROGRAM-ID']: 1,
RESOLUTION: {
height: 600,
width: 800
}
},
endList: true,
resolvedUri: '',
segments: [{
uri: '',
timeline: 1,
duration: 2,
resolvedUri: '',
map: {
uri: '',
resolvedUri: ''
}
}, {
uri: '',
timeline: 1,
duration: 2,
resolvedUri: '',
map: {
uri: '',
resolvedUri: ''
}
}],
timeline: 1,
uri: ''
}],
segments: [],
uri: ''
};

assert.deepEqual(toM3u8(input), expected);
});

QUnit.test('no playlists', function(assert) {
assert.deepEqual(toM3u8([]), {});
});

0 comments on commit 4068790

Please sign in to comment.