Skip to content

Commit

Permalink
test: cover hlsPlayback merge case
Browse files Browse the repository at this point in the history
  • Loading branch information
joaopaulovieira committed Jan 31, 2021
1 parent 2261b00 commit 30ffda2
Showing 1 changed file with 39 additions and 42 deletions.
81 changes: 39 additions & 42 deletions src/hls.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,48 +43,6 @@ describe('HlsjsPlayback', () => {
expect(playback.tagName).toEqual('audio')
})

describe('options backwards compatibility', () => {
// backwards compatibility (TODO: remove on 0.3.0)
test('should set options.playback as a reference to options if options.playback not set', () => {
let options = { src: 'http://clappr.io/video.m3u8' },
hls = new HlsjsPlayback(options)
expect(hls.options.playback).toEqual(hls.options)
options = { src: 'http://clappr.io/video.m3u8', playback: { test: true } }
hls = new HlsjsPlayback(options)
expect(hls.options.playback.test).toEqual(true)
})
})

describe('HlsjsPlayback.js configuration', () => {
test('should use hlsjsConfig from playback options', () => {
const options = {
src: 'http://clappr.io/video.m3u8',
playback: {
hlsMinimumDvrSize: 1,
hlsjsConfig: {
someHlsjsOption: 'value'
}
}
}
const playback = new HlsjsPlayback(options)
playback._setup()
expect(playback._hls.config.someHlsjsOption).toEqual('value')
})

test('should use hlsjsConfig from player options as fallback', () => {
const options = {
src: 'http://clappr.io/video.m3u8',
hlsMinimumDvrSize: 1,
hlsjsConfig: {
someHlsjsOption: 'value'
}
}
const playback = new HlsjsPlayback(options)
playback._setup()
expect(playback._hls.config.someHlsjsOption).toEqual('value')
})
})

test('should trigger a playback error if source load failed', () => {
jest.spyOn(window.HTMLMediaElement.prototype, 'play').mockImplementation(() => {})
let resolveFn = undefined
Expand Down Expand Up @@ -137,4 +95,43 @@ describe('HlsjsPlayback', () => {
expect(playback.currentLevel).toEqual(1)
expect(playback._hls.currentLevel).toEqual(1)
})

describe('constructor', () => {
test('should use hlsjsConfig from playback options', () => {
const options = {
src: 'http://clappr.io/video.m3u8',
playback: {
hlsMinimumDvrSize: 1,
hlsjsConfig: {
someHlsjsOption: 'value'
}
}
}
const playback = new HlsjsPlayback(options)
playback._setup()
expect(playback._hls.config.someHlsjsOption).toEqual('value')
})

test('should use hlsjsConfig from player options as fallback', () => {
const options = {
src: 'http://clappr.io/video.m3u8',
hlsMinimumDvrSize: 1,
hlsjsConfig: {
someHlsjsOption: 'value'
}
}
const playback = new HlsjsPlayback(options)
playback._setup()
expect(playback._hls.config.someHlsjsOption).toEqual('value')
})

test('merges defaultOptions with received options.hlsPlayback', () => {
const options = {
src: 'http://clappr.io/foo.m3u8',
hlsjsPlayback: { foo: 'bar' },
}
const playback = new HlsjsPlayback(options)
expect(playback.options.hlsPlayback).toEqual({ ...options.hlsPlayback, ...playback.defaultOptions })
})
})
})

0 comments on commit 30ffda2

Please sign in to comment.