-
Notifications
You must be signed in to change notification settings - Fork 32
Test/texttrack cue test #899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
94fd214
Update local ios test scripts
wvanhaevre e179775
Add textTrack cues test
wvanhaevre d96f357
chore: retrigger CI
devin-ai-integration[bot] 3020a27
Update textTrack test to a sideloaded vtt setup
wvanhaevre b87ca87
Test both sideloaded and internal textTrack setups.
wvanhaevre 0f5bdd9
Use HLS for sideloaded subtitle test
wvanhaevre 49559cf
Enable sideloaded subtitles in E2E builds
wvanhaevre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "ios": { | ||
| "features": ["GOOGLE_IMA", "CHROMECAST", "THEO_ADS", "MILLICAST"] | ||
| "features": ["GOOGLE_IMA", "CHROMECAST", "SIDELOADED_TEXTTRACKS", "THEO_ADS", "MILLICAST"] | ||
| } | ||
| } |
This file contains hidden or 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,56 @@ | ||
| # Local e2e test scripts | ||
|
|
||
| Helper scripts for running the react-native-theoplayer e2e suite locally. | ||
|
|
||
| > Run these from inside `e2e/scripts/` — they `cd ..` internally and rely on | ||
| > relative paths. | ||
|
|
||
| ## iOS: `e2e_ios.sh` | ||
|
|
||
| Drives the iOS run through three stages: | ||
|
|
||
| - **prepare** (`prep_e2e_tests.sh`) — clears screenshots, reinstalls | ||
| `node_modules` and Pods, and swaps in the test entry point (`index.test.js` | ||
| becomes `index.js`, the original is backed up as `index_old.js`). | ||
| - **run** (`run_ios_e2e_tests.sh`) — builds and runs the suite on the iOS | ||
| simulator via `cavynext`, writing output to `ios_output.txt`. | ||
| - **reset** (`reset_e2e_tests.sh`) — restores the original `index.js`, undoing | ||
| the prepare stage. | ||
|
|
||
| ### Usage | ||
|
|
||
| ```sh | ||
| ./e2e_ios.sh # full cycle: prepare -> run -> reset | ||
| ./e2e_ios.sh rerun # run only (reuse an already prepared setup) | ||
| ./e2e_ios.sh reset # reset only (restore the original setup) | ||
| ``` | ||
|
|
||
| ### Iterating quickly | ||
|
|
||
| `prepare` is the slow stage (`npm i`, `pod update`). Once it has run, the setup | ||
| persists, so you can retest repeatedly with `rerun`: | ||
|
|
||
| ```sh | ||
| ./e2e_ios.sh # prepare once ... (runs and then resets) | ||
| # — or run prepare without the trailing reset, then: | ||
| ./e2e_ios.sh rerun # re-run as many times as you like | ||
| ./e2e_ios.sh reset # restore when finished | ||
| ``` | ||
|
|
||
| Editing test spec files (`src/tests/*.spec.ts`) between `rerun`s is fine — | ||
| `cavynext` rebuilds the JS bundle from source each run. A fresh `prepare` is | ||
| only needed after adding/upgrading npm dependencies or changing native code. | ||
|
|
||
| **Caveats while in the prepared state:** | ||
|
|
||
| - Do **not** run `reset` between `rerun`s — it swaps the stub entry point back, | ||
| so the next run would launch the non-test app. | ||
| - Do **not** run `prepare` again before `reset` — it would overwrite the | ||
| `index_old.js` backup with the (already swapped-in) test entry, losing the | ||
| original. | ||
|
|
||
| ## Web: `run_web_e2e.sh` | ||
|
|
||
| Used as the `buildCmd` for `cavynext run-web` (see the `test:e2e:web` npm | ||
| script). It starts the webpack dev server and opens the app in a dedicated | ||
| Chrome instance with autoplay/throttling flags suitable for the test run. |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,2 +1,10 @@ | ||
| #!/bin/sh | ||
| ./prep_e2e_tests.sh && ./run_ios_e2e_tests.sh && ./reset_e2e_tests.sh | ||
| if [ "$1" = "rerun" ]; then | ||
| # Re-run the tests against an already prepared setup, skipping prepare/reset. | ||
| ./run_ios_e2e_tests.sh | ||
| elif [ "$1" = "reset" ]; then | ||
| # Only restore the original setup (undo a previous prepare). | ||
| ./reset_e2e_tests.sh | ||
| else | ||
| ./prep_e2e_tests.sh && ./run_ios_e2e_tests.sh && ./reset_e2e_tests.sh | ||
| fi | ||
This file contains hidden or 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,96 @@ | ||
| import { expect, TestScope } from 'react-native-cavynext'; | ||
| import { | ||
| PlayerEventType, | ||
| SourceDescription, | ||
| TextTrack, | ||
| TextTrackEvent, | ||
| TextTrackEventType, | ||
| TextTrackKind, | ||
| THEOplayer, | ||
| } from 'react-native-theoplayer'; | ||
| import { preparePlayerWithSource, seekTo, waitForPlayerEvents } from '../utils/Actions'; | ||
| import { sleep } from '../utils/TimeUtils'; | ||
|
|
||
| const SIDE_LOADED_SOURCE: SourceDescription = { | ||
| sources: { | ||
| src: 'https://cdn.theoplayer.com/video/sintel/nosubs.m3u8', | ||
| type: 'application/x-mpegurl', | ||
| }, | ||
| textTracks: [ | ||
| { | ||
| src: 'https://cdn.theoplayer.com/video/elephant/elephants-dream-subtitles-nl.vtt', | ||
| kind: TextTrackKind.subtitles, | ||
| srclang: 'nl', | ||
| label: 'Dutch', | ||
| format: 'webvtt', | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const HLS_SOURCE: SourceDescription = { | ||
| sources: { | ||
| src: 'https://cdn.theoplayer.com/video/tears_of_steel/index.m3u8', | ||
| type: 'application/x-mpegurl', | ||
| }, | ||
| }; | ||
|
|
||
| const CUE_TIMEOUT = { timeout: 30000 }; | ||
|
|
||
| export default function (spec: TestScope) { | ||
| spec.describe('Text tracks', () => { | ||
| spec.it('reports active cues from a side-loaded WebVTT track', async () => { | ||
| await expectCueEvents(spec, SIDE_LOADED_SOURCE, ['nl'], 'nl', 13e3); | ||
| }); | ||
|
|
||
| spec.it('reports active cues from a WebVTT track declared by an HLS manifest', async () => { | ||
| await expectCueEvents(spec, HLS_SOURCE, ['cn', 'de', 'en', 'fr', 'nl'], 'nl', 21e3); | ||
|
wvanhaevre marked this conversation as resolved.
|
||
| }); | ||
| }); | ||
| } | ||
|
|
||
| async function expectCueEvents( | ||
| spec: TestScope, | ||
| source: SourceDescription, | ||
| expectedLanguages: string[], | ||
| selectedLanguage: string, | ||
| seekTime: number, | ||
| ): Promise<void> { | ||
| const player = await preparePlayerWithSource(spec, source); | ||
| const subtitleTracks = await waitForSubtitleTracks(player, expectedLanguages.length); | ||
| const languages = subtitleTracks.map((track) => track.language); | ||
| expectedLanguages.forEach((language) => expect(languages).toContain(language)); | ||
|
|
||
| const selectedTrack = subtitleTracks.find((track) => track.language === selectedLanguage)!; | ||
| const cueEventsPromise = waitForPlayerEvents( | ||
| player, | ||
| [ | ||
| { type: PlayerEventType.TEXT_TRACK, subType: TextTrackEventType.ADD_CUE, trackUid: selectedTrack.uid } as Partial<TextTrackEvent>, | ||
| { type: PlayerEventType.TEXT_TRACK, subType: TextTrackEventType.ENTER_CUE, trackUid: selectedTrack.uid } as Partial<TextTrackEvent>, | ||
| { type: PlayerEventType.TEXT_TRACK, subType: TextTrackEventType.EXIT_CUE, trackUid: selectedTrack.uid } as Partial<TextTrackEvent>, | ||
| ], | ||
| false, | ||
| CUE_TIMEOUT, | ||
| ); | ||
| player.selectedTextTrack = selectedTrack.uid; | ||
|
|
||
| await seekTo(player, seekTime); | ||
| await cueEventsPromise; | ||
| } | ||
|
|
||
| // Poll `player.textTracks` until the expected number of subtitle tracks is | ||
| // available, since they populate on `loadedmetadata` rather than at source set. | ||
| async function waitForSubtitleTracks(player: THEOplayer, count: number, timeout = 30e3): Promise<TextTrack[]> { | ||
| const deadline = Date.now() + timeout; | ||
| while (Date.now() < deadline) { | ||
| const subtitles = player.textTracks.filter((track) => track.kind === TextTrackKind.subtitles); | ||
| if (subtitles.length >= count) { | ||
| return subtitles; | ||
| } | ||
| await sleep(250); | ||
| } | ||
| throw new Error( | ||
| `Timed out waiting for ${count} subtitle tracks; got ${JSON.stringify( | ||
| player.textTracks.map(({ uid, kind, language, label, type }) => ({ uid, kind, language, label, type })), | ||
| )}`, | ||
| ); | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.