1 | import QUnit from 'qunit';
|
2 | import xhrFactory from '../src/xhr';
|
3 | import { useFakeEnvironment } from './test-helpers.js';
|
4 | import videojs from 'video.js';
|
5 |
|
6 | QUnit.module('xhr', {
|
7 | beforeEach(assert) {
|
8 | this.env = useFakeEnvironment(assert);
|
9 | this.clock = this.env.clock;
|
10 | this.requests = this.env.requests;
|
11 | this.xhr = xhrFactory();
|
12 | },
|
13 | afterEach() {
|
14 | this.env.restore();
|
15 | }
|
16 | });
|
17 |
|
18 | QUnit.test('xhr respects beforeRequest', function(assert) {
|
19 | let defaultOptions = {
|
20 | url: 'default'
|
21 | };
|
22 |
|
23 | this.xhr(defaultOptions);
|
24 | assert.equal(this.requests.shift().url, 'default', 'url the same without override');
|
25 |
|
26 | this.xhr.beforeRequest = (options) => {
|
27 | options.url = 'player';
|
28 | return options;
|
29 | };
|
30 |
|
31 | this.xhr(defaultOptions);
|
32 | assert.equal(this.requests.shift().url, 'player', 'url changed with player override');
|
33 |
|
34 | videojs.Hls.xhr.beforeRequest = (options) => {
|
35 | options.url = 'global';
|
36 | return options;
|
37 | };
|
38 |
|
39 | this.xhr(defaultOptions);
|
40 | assert.equal(this.requests.shift().url, 'player', 'prioritizes player override');
|
41 |
|
42 | delete this.xhr.beforeRequest;
|
43 |
|
44 | this.xhr(defaultOptions);
|
45 | assert.equal(this.requests.shift().url, 'global', 'url changed with global override');
|
46 | });
|