Skip to content

Commit

Permalink
tests: begin removing XHRMock util
Browse files Browse the repository at this point in the history
This is a Work-In-Progress to remove the `XHRMock` utils from our tests,
which monkey-patched the browser's `XMLHttpRequest` API to allow mocking
requests, "locking" them, redirecting them and so on (kind of like
sinon.js's [nise](https://github.com/sinonjs/nise) which was a major
inspiration but with added locking/unlocking capabilities).

The reasons for doing this are:

  - It only worked for `XMLHttpRequest` and not for the `fetch` browser
    API which we use to fetch low-latency segments for now (due to some
    API differences between the two) and plan to use for more things in
    the future.

    Adding support for `fetch` looks like huge work (we have to
    re-implement the most part of the API in JS - may be fun but there
    are funnier tasks which are also more useful :p)

  - We have RxPlayer API which allows an application to provide its own
    fetching logic (`manifestLoader` and `segmentLoader`) which covers
    almost all fetching cases (it does not cover XLink charging,
    low-latency segment fetching and future Content Steering Manifest
    fetching) and covers all fetching cases currently done by `XHRMock`.

  - The now probable incoming future in-Worker feature of the RxPlayer
    cannot easily rely on monkey-patching its API, at least in integration
    tests (well, in all honesty, we will have to think about how we'll be
    testing this feature).

  - It was complex, looked like an NIH-y `fakeServer` implementation.

    Removing it in favor or simpler solutions is just easier to
    understand.

This is not completely done yet.
  • Loading branch information
peaBerberian committed Nov 7, 2023
1 parent 23cbde3 commit 5ede134
Show file tree
Hide file tree
Showing 25 changed files with 678 additions and 1,673 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<MPD availabilityStartTime="1970-01-01T00:00:00Z" id="Config part of url maybe?" maxSegmentDuration="PT2S" minBufferTime="PT2S" minimumUpdatePeriod="PT1795S" profiles="urn:mpeg:dash:profile:isoff-live:2011,http://dashif.org/guidelines/dash-if-simple" publishTime="2019-03-25T12:49:14Z" timeShiftBufferDepth="PT5M" type="dynamic" ns1:schemaLocation="urn:mpeg:dash:schema:mpd:2011 DASH-MPD.xsd" xmlns="urn:mpeg:dash:schema:mpd:2011" xmlns:ns1="http://www.w3.org/2001/XMLSchema-instance">
<!-- TODO NOTE: This for now needs to be replaced manually if the port ever changes :/ -->
<UTCTiming
schemeIdUri="urn:mpeg:dash:utc:http-iso:2014"
value="https://time.akamai.com/?iso" />
schemeIdUri="urn:mpeg:dash:utc:http-iso:2014"
value="http://127.0.0.1:3000/time" />
<ProgramInformation>
<Title>Media Presentation Description from DASHI-IF live simulator</Title>
</ProgramInformation>
Expand Down
5 changes: 5 additions & 0 deletions tests/contents/DASH_dynamic_UTCTimings/urls.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,9 @@ export default [
path: path.join(currentDirectory, "./media/V300/776759079.m4s"),
contentType: "audio/mp4",
},
{
url: "/time",
data: "2019-05-25T13:49:08.014Z",
contentType: "text/plain",
},
];
4 changes: 0 additions & 4 deletions tests/integration/scenarios/dash_forced-subtitles.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ import RxPlayer from "../../../src";
import {
forcedSubtitles,
} from "../../contents/DASH_static_SegmentTimeline";
import XHRMock from "../../utils/request_mock";
import {
waitForLoadedStateAfterLoadVideo,
} from "../../utils/waitForPlayerState";

describe("DASH forced-subtitles content (SegmentTimeline)", function () {
let player;
let xhrMock;

async function loadContent() {
player.loadVideo({ url: forcedSubtitles.url,
Expand Down Expand Up @@ -44,12 +42,10 @@ describe("DASH forced-subtitles content (SegmentTimeline)", function () {
beforeEach(() => {
player = new RxPlayer();
player.setWantedBufferAhead(5); // We don't really care
xhrMock = new XHRMock();
});

afterEach(() => {
player.dispose();
xhrMock.restore();
});

it("should use the forced text track linked to the default audio track by default", async function () {
Expand Down
Loading

0 comments on commit 5ede134

Please sign in to comment.