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 Sep 29, 2023
1 parent fd7ef33 commit fc8c99c
Show file tree
Hide file tree
Showing 8 changed files with 316 additions and 171 deletions.
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 fc8c99c

Please sign in to comment.