From b9921671223fb44ab86b0a9d23cc039df8efd003 Mon Sep 17 00:00:00 2001 From: Brandon Casey <2381475+brandonocasey@users.noreply.github.com> Date: Tue, 26 Oct 2021 11:19:37 -0400 Subject: [PATCH] test: cleanup xhr correctly (#150) --- test/eme.test.js | 9 ++++++++- test/fairplay.test.js | 13 ++++++++++++- test/plugin.test.js | 7 +++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/test/eme.test.js b/test/eme.test.js index e374525..d1be434 100644 --- a/test/eme.test.js +++ b/test/eme.test.js @@ -46,7 +46,14 @@ const resolveReject = (rejectVariable, rejectMessage) => { }); }; -QUnit.module('videojs-contrib-eme eme'); +QUnit.module('videojs-contrib-eme eme', { + beforeEach() { + this.origXhr = videojs.xhr; + }, + afterEach() { + videojs.xhr = this.origXhr; + } +}); QUnit.test('keystatuseschange triggers keystatuschange on eventBus for each key', function(assert) { const callCount = {total: 0, 1: {}, 2: {}, 3: {}, 4: {}, 5: {}}; diff --git a/test/fairplay.test.js b/test/fairplay.test.js index 949c7e7..ec2e01e 100644 --- a/test/fairplay.test.js +++ b/test/fairplay.test.js @@ -9,7 +9,18 @@ import videojs from 'video.js'; import window from 'global/window'; import { getMockEventBus } from './utils'; -QUnit.module('videojs-contrib-eme fairplay'); +QUnit.module('videojs-contrib-eme fairplay', { + beforeEach() { + this.origXhr = videojs.xhr; + + videojs.xhr = (params, callback) => { + return callback(null, {statusCode: 200}, new Uint8Array([0, 1, 2, 3]).buffer); + }; + }, + afterEach() { + videojs.xhr = this.origXhr; + } +}); QUnit.test('lifecycle', function(assert) { assert.expect(23); diff --git a/test/plugin.test.js b/test/plugin.test.js index 6c357af..11cf71b 100644 --- a/test/plugin.test.js +++ b/test/plugin.test.js @@ -362,6 +362,12 @@ QUnit.module('plugin guard functions', { } }; + this.origXhr = videojs.xhr; + + videojs.xhr = (params, callback) => { + return callback(null, {statusCode: 200}, new Uint8Array([0, 1, 2, 3]).buffer); + }; + this.initData1 = new Uint8Array([1, 2, 3]).buffer; this.initData2 = new Uint8Array([4, 5, 6]).buffer; @@ -398,6 +404,7 @@ QUnit.module('plugin guard functions', { }, afterEach() { window.navigator.requestMediaKeySystemAccess = this.origRequestMediaKeySystemAccess; + videojs.xhr = this.origXhr; } });