-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from eliotjordan/91-hls-fix
Fix HLS format detection
- Loading branch information
Showing
9 changed files
with
12,409 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,5 @@ dist-umd | |
dist-var | ||
types | ||
.vitest-result.json | ||
.tool-versions | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ruby 3.1.0 | ||
nodejs 16.15.0 | ||
java zulu-8.58.0.13 | ||
python 3.9.1 | ||
yarn 1.22.10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { beforeEach, describe, expect, vitest, test } from 'vitest' | ||
import { canPlayHls } from '../src/helpers/can-play-hls' | ||
|
||
describe('canPlayHls', () => { | ||
describe('with a browser that natively supports HLS', () => { | ||
beforeEach(() => { | ||
window.HTMLMediaElement.prototype.canPlayType = vitest.fn((_type) => { | ||
return "probably" | ||
}) | ||
}) | ||
|
||
test('returns true', () => { | ||
expect(canPlayHls()).toBeTruthy() | ||
}) | ||
}) | ||
|
||
describe('with a browser that does not natively support HLS', () => { | ||
beforeEach(() => { | ||
window.HTMLMediaElement.prototype.canPlayType = vitest.fn((_type) => { | ||
return "" | ||
}) | ||
}) | ||
|
||
test('returns false', () => { | ||
expect(canPlayHls()).toBeFalsy() | ||
}) | ||
}) | ||
|
||
describe('with a browser that does not natively support HLS but is using HLS.js', () => { | ||
beforeEach(() => { | ||
class Hls { | ||
isSupported() { return true } | ||
} | ||
|
||
window.HTMLMediaElement.prototype.canPlayType = vitest.fn((_type) => { | ||
return "" | ||
}) | ||
window.Hls = new Hls | ||
}) | ||
|
||
test('returns true', () => { | ||
expect(canPlayHls()).toBeTruthy() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { beforeEach, describe, expect, vitest, test } from 'vitest'; | ||
import { HlsFormat } from '../src/media-formats/hls-format'; | ||
|
||
describe('HlsFormat', () => { | ||
class HlsClassMock { | ||
loadSource() {} | ||
attachMedia() {} | ||
} | ||
|
||
afterEach(() => { | ||
vitest.unstubAllGlobals() | ||
}) | ||
|
||
describe('when hls.js is included', () => { | ||
test('hls attaches the media element', () => { | ||
vitest.stubGlobal('Hls', HlsClassMock); | ||
const attachMediaSpy = vitest.spyOn(HlsClassMock.prototype, 'attachMedia'); | ||
const loadSourceSpy = vitest.spyOn(HlsClassMock.prototype, 'loadSource'); | ||
const format = new HlsFormat(); | ||
format.attachTo(); | ||
expect(loadSourceSpy).toHaveBeenCalled(); | ||
expect(attachMediaSpy).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('when hls.js is not included', () => { | ||
test('hls attaches the media element', () => { | ||
const attachMediaSpy = vitest.spyOn(HlsClassMock.prototype, 'attachMedia'); | ||
const loadSourceSpy = vitest.spyOn(HlsClassMock.prototype, 'loadSource'); | ||
const format = new HlsFormat(); | ||
format.attachTo(); | ||
expect(loadSourceSpy).not.toHaveBeenCalled(); | ||
expect(attachMediaSpy).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.