Skip to content

Commit

Permalink
Add common constant GET_METHOD for tests
Browse files Browse the repository at this point in the history
Remove unnecessary MPD_PATH
  • Loading branch information
AdamWr committed Oct 13, 2022
1 parent 63c4bef commit fe26660
Showing 1 changed file with 17 additions and 37 deletions.
54 changes: 17 additions & 37 deletions tests/scriptlets/xml-prune.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { test, module } = QUnit;
const name = 'xml-prune';

const MPD_OBJECTS_PATH = './test-files/manifestMPD.mpd';
const GET_METHOD = 'GET';
const nativeFetch = fetch;
const nativeXhrOpen = XMLHttpRequest.prototype.open;
const nativeConsole = console.log;
Expand Down Expand Up @@ -51,22 +52,21 @@ if (!isSupported) {
});

test('fetch - no prune (log)', async (assert) => {
const MPD_PATH = `${MPD_OBJECTS_PATH}`;
const done = assert.async();

// mock console.log function for log checking
console.log = function log(input) {
if (input.indexOf('trace') > -1) {
return;
}
const EXPECTED_LOG_STR_START = `fetch URL: ${MPD_PATH}`;
const EXPECTED_LOG_STR_START = `fetch URL: ${MPD_OBJECTS_PATH}`;
assert.ok(startsWith(input, EXPECTED_LOG_STR_START), 'console.hit input');
assert.ok(input.indexOf('pre-roll-1-ad-1') > -1);
};

runScriptlet(name);

const response = await fetch(MPD_PATH);
const response = await fetch(MPD_OBJECTS_PATH);
const responseMPD = await response.text();

assert.ok(responseMPD.indexOf('pre-roll-1-ad-1') > -1);
Expand All @@ -75,7 +75,6 @@ if (!isSupported) {
});

test('fetch URL does not match - no prune', async (assert) => {
const MPD_PATH = `${MPD_OBJECTS_PATH}`;
const MATCH_DATA = "Period[id*='-ad-']";
const OPTIONAL_MATCH = '';
const MATCH_URL = 'noPrune';
Expand All @@ -85,7 +84,7 @@ if (!isSupported) {

const done = assert.async();

const response = await fetch(MPD_PATH);
const response = await fetch(MPD_OBJECTS_PATH);
const responseMPD = await response.text();

assert.ok(responseMPD.indexOf('pre-roll-1-ad-1') > -1);
Expand All @@ -94,7 +93,6 @@ if (!isSupported) {
});

test('fetch match URL, element to remove does not match - no prune', async (assert) => {
const MPD_PATH = `${MPD_OBJECTS_PATH}`;
const MATCH_DATA = "Period[id*='do-no-match']";
const OPTIONAL_MATCH = '';
const MATCH_URL = '.mpd';
Expand All @@ -104,7 +102,7 @@ if (!isSupported) {

const done = assert.async();

const response = await fetch(MPD_PATH);
const response = await fetch(MPD_OBJECTS_PATH);
const responseMPD = await response.text();

assert.ok(responseMPD.indexOf('pre-roll-1-ad-1') > -1);
Expand All @@ -113,7 +111,6 @@ if (!isSupported) {
});

test('fetch match URL, optional argument does not match - no prune', async (assert) => {
const MPD_PATH = `${MPD_OBJECTS_PATH}`;
const MATCH_DATA = "Period[id*='-ad-']";
const OPTIONAL_MATCH = 'DO_NOT_MATCH';
const MATCH_URL = '.mpd';
Expand All @@ -123,7 +120,7 @@ if (!isSupported) {

const done = assert.async();

const response = await fetch(MPD_PATH);
const response = await fetch(MPD_OBJECTS_PATH);
const responseMPD = await response.text();

assert.ok(responseMPD.indexOf('pre-roll-1-ad-1') > -1);
Expand All @@ -132,14 +129,13 @@ if (!isSupported) {
});

test('fetch - remove ads', async (assert) => {
const MPD_PATH = `${MPD_OBJECTS_PATH}`;
const MATCH_DATA = ["Period[id*='-ad-']"];

runScriptlet(name, MATCH_DATA);

const done = assert.async();

const response = await fetch(MPD_PATH);
const response = await fetch(MPD_OBJECTS_PATH);
const responseMPD = await response.text();

assert.notOk(responseMPD.indexOf('pre-roll-1-ad-1') > -1);
Expand All @@ -148,7 +144,6 @@ if (!isSupported) {
});

test('fetch match URL - remove ads', async (assert) => {
const MPD_PATH = `${MPD_OBJECTS_PATH}`;
const MATCH_DATA = "Period[id*='-ad-']";
const OPTIONAL_MATCH = '';
const MATCH_URL = '.mpd';
Expand All @@ -158,7 +153,7 @@ if (!isSupported) {

const done = assert.async();

const response = await fetch(MPD_PATH);
const response = await fetch(MPD_OBJECTS_PATH);
const responseMPD = await response.text();

assert.notOk(responseMPD.indexOf('pre-roll-1-ad-1') > -1);
Expand All @@ -167,7 +162,6 @@ if (!isSupported) {
});

test('fetch match URL, match optional argument - remove ads', async (assert) => {
const MPD_PATH = `${MPD_OBJECTS_PATH}`;
const MATCH_DATA = "Period[id*='-ad-']";
const OPTIONAL_MATCH = 'AdaptationSet';
const MATCH_URL = '.mpd';
Expand All @@ -177,7 +171,7 @@ if (!isSupported) {

const done = assert.async();

const response = await fetch(MPD_PATH);
const response = await fetch(MPD_OBJECTS_PATH);
const responseMPD = await response.text();

assert.notOk(responseMPD.indexOf('pre-roll-1-ad-1') > -1);
Expand All @@ -186,23 +180,21 @@ if (!isSupported) {
});

test('xhr - no prune (log)', async (assert) => {
const METHOD = 'GET';
const MPD_PATH = `${MPD_OBJECTS_PATH}`;
const done = assert.async();

console.log = function log(input) {
if (input.indexOf('trace') > -1) {
return;
}
const EXPECTED_LOG_STR_START = `XMLHttpRequest.open() URL: ${MPD_PATH}`;
const EXPECTED_LOG_STR_START = `XMLHttpRequest.open() URL: ${MPD_OBJECTS_PATH}`;
assert.ok(startsWith(input, EXPECTED_LOG_STR_START), 'console.hit input');
assert.ok(input.indexOf('pre-roll-1-ad-1') > -1, 'console.hit input');
};

runScriptlet(name);

const xhr = new XMLHttpRequest();
xhr.open(METHOD, MPD_PATH);
xhr.open(GET_METHOD, MPD_OBJECTS_PATH);
xhr.onload = () => {
assert.ok(xhr.responseText.indexOf('pre-roll-1-ad-1') > -1);
assert.strictEqual(window.hit, undefined, 'should not hit');
Expand All @@ -212,8 +204,6 @@ if (!isSupported) {
});

test('xhr URL does not match - no prune', async (assert) => {
const METHOD = 'GET';
const MPD_PATH = `${MPD_OBJECTS_PATH}`;
const MATCH_DATA = "Period[id*='-ad-']";
const OPTIONAL_MATCH = '';
const MATCH_URL = 'noPrune';
Expand All @@ -224,7 +214,7 @@ if (!isSupported) {
const done = assert.async();

const xhr = new XMLHttpRequest();
xhr.open(METHOD, MPD_PATH);
xhr.open(GET_METHOD, MPD_OBJECTS_PATH);
xhr.onload = () => {
assert.ok(xhr.responseText.indexOf('pre-roll-1-ad-1') > -1);
assert.strictEqual(window.hit, undefined, 'should not hit');
Expand All @@ -234,8 +224,6 @@ if (!isSupported) {
});

test('xhr match URL, element to remove does not match - no prune', async (assert) => {
const METHOD = 'GET';
const MPD_PATH = `${MPD_OBJECTS_PATH}`;
const MATCH_DATA = "Period[id*='do-no-match']";
const OPTIONAL_MATCH = '';
const MATCH_URL = '.mpd';
Expand All @@ -246,7 +234,7 @@ if (!isSupported) {
const done = assert.async();

const xhr = new XMLHttpRequest();
xhr.open(METHOD, MPD_PATH);
xhr.open(GET_METHOD, MPD_OBJECTS_PATH);
xhr.onload = () => {
assert.ok(xhr.responseText.indexOf('pre-roll-1-ad-1') > -1);
assert.strictEqual(window.hit, 'FIRED', 'hit function fired');
Expand All @@ -256,8 +244,6 @@ if (!isSupported) {
});

test('xhr match URL, optional argument does not match - no prune', async (assert) => {
const METHOD = 'GET';
const MPD_PATH = `${MPD_OBJECTS_PATH}`;
const MATCH_DATA = "Period[id*='-ad-']";
const OPTIONAL_MATCH = 'DO_NOT_MATCH';
const MATCH_URL = '.mpd';
Expand All @@ -268,7 +254,7 @@ if (!isSupported) {
const done = assert.async();

const xhr = new XMLHttpRequest();
xhr.open(METHOD, MPD_PATH);
xhr.open(GET_METHOD, MPD_OBJECTS_PATH);
xhr.onload = () => {
assert.ok(xhr.responseText.indexOf('pre-roll-1-ad-1') > -1);
assert.strictEqual(window.hit, 'FIRED', 'hit function fired');
Expand All @@ -278,16 +264,14 @@ if (!isSupported) {
});

test('xhr - remove ads', async (assert) => {
const METHOD = 'GET';
const MPD_PATH = `${MPD_OBJECTS_PATH}`;
const MATCH_DATA = ["Period[id*='-ad-']"];

runScriptlet(name, MATCH_DATA);

const done = assert.async();

const xhr = new XMLHttpRequest();
xhr.open(METHOD, MPD_PATH);
xhr.open(GET_METHOD, MPD_OBJECTS_PATH);
xhr.onload = () => {
assert.notOk(xhr.responseText.indexOf('pre-roll-1-ad-1') > -1);
assert.strictEqual(window.hit, 'FIRED', 'hit function fired');
Expand All @@ -297,8 +281,6 @@ if (!isSupported) {
});

test('xhr match URL - remove ads', async (assert) => {
const METHOD = 'GET';
const MPD_PATH = `${MPD_OBJECTS_PATH}`;
const MATCH_DATA = "Period[id*='-ad-']";
const OPTIONAL_MATCH = '';
const MATCH_URL = '.mpd';
Expand All @@ -309,7 +291,7 @@ if (!isSupported) {
const done = assert.async();

const xhr = new XMLHttpRequest();
xhr.open(METHOD, MPD_PATH);
xhr.open(GET_METHOD, MPD_OBJECTS_PATH);
xhr.onload = () => {
assert.notOk(xhr.responseText.indexOf('pre-roll-1-ad-1') > -1);
assert.strictEqual(window.hit, 'FIRED', 'hit function fired');
Expand All @@ -319,8 +301,6 @@ if (!isSupported) {
});

test('xhr match URL, match optional argument - remove ads', async (assert) => {
const METHOD = 'GET';
const MPD_PATH = `${MPD_OBJECTS_PATH}`;
const MATCH_DATA = "Period[id*='-ad-']";
const OPTIONAL_MATCH = 'AdaptationSet';
const MATCH_URL = '.mpd';
Expand All @@ -331,7 +311,7 @@ if (!isSupported) {
const done = assert.async();

const xhr = new XMLHttpRequest();
xhr.open(METHOD, MPD_PATH);
xhr.open(GET_METHOD, MPD_OBJECTS_PATH);
xhr.onload = () => {
assert.notOk(xhr.responseText.indexOf('pre-roll-1-ad-1') > -1);
assert.strictEqual(window.hit, 'FIRED', 'hit function fired');
Expand Down

0 comments on commit fe26660

Please sign in to comment.