mirror of
https://github.com/videojs/video.js.git
synced 2025-01-13 10:32:26 +02:00
fix: extra warn logs on already initialized player references (#3888)
This commit is contained in:
parent
4fd902229f
commit
b7c384eb5b
@ -65,8 +65,6 @@ if (typeof HTMLVideoElement === 'undefined' &&
|
|||||||
function videojs(id, options, ready) {
|
function videojs(id, options, ready) {
|
||||||
let tag;
|
let tag;
|
||||||
|
|
||||||
options = options || {};
|
|
||||||
|
|
||||||
// Allow for element or ID to be passed in
|
// Allow for element or ID to be passed in
|
||||||
// String ID
|
// String ID
|
||||||
if (typeof id === 'string') {
|
if (typeof id === 'string') {
|
||||||
@ -111,6 +109,8 @@ function videojs(id, options, ready) {
|
|||||||
return tag.player || Player.players[tag.playerId];
|
return tag.player || Player.players[tag.playerId];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
options = options || {};
|
||||||
|
|
||||||
videojs.hooks('beforesetup').forEach(function(hookFunction) {
|
videojs.hooks('beforesetup').forEach(function(hookFunction) {
|
||||||
const opts = hookFunction(tag, mergeOptions(options));
|
const opts = hookFunction(tag, mergeOptions(options));
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
import videojs from '../../src/js/video.js';
|
import videojs from '../../src/js/video.js';
|
||||||
import TestHelpers from './test-helpers.js';
|
import TestHelpers from './test-helpers.js';
|
||||||
import * as Dom from '../../src/js/utils/dom.js';
|
import * as Dom from '../../src/js/utils/dom.js';
|
||||||
|
import log from '../../src/js/utils/log.js';
|
||||||
import document from 'global/document';
|
import document from 'global/document';
|
||||||
|
|
||||||
QUnit.module('video.js');
|
QUnit.module('video.js');
|
||||||
@ -45,6 +46,44 @@ QUnit.test('should return a video player instance', function(assert) {
|
|||||||
player2.dispose();
|
player2.dispose();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test('should log about already initalized players if options already passed',
|
||||||
|
function(assert) {
|
||||||
|
const origWarnLog = log.warn;
|
||||||
|
const fixture = document.getElementById('qunit-fixture');
|
||||||
|
const warnLogs = [];
|
||||||
|
|
||||||
|
log.warn = (args) => {
|
||||||
|
warnLogs.push(args);
|
||||||
|
};
|
||||||
|
|
||||||
|
fixture.innerHTML += '<video id="test_vid_id"></video>';
|
||||||
|
|
||||||
|
const player = videojs('test_vid_id', { techOrder: ['techFaker'] });
|
||||||
|
|
||||||
|
assert.ok(player, 'created player from tag');
|
||||||
|
assert.equal(player.id(), 'test_vid_id', 'player has the right ID');
|
||||||
|
assert.equal(warnLogs.length, 0, 'no warn logs');
|
||||||
|
|
||||||
|
const playerAgain = videojs('test_vid_id');
|
||||||
|
|
||||||
|
assert.equal(player, playerAgain, 'did not create a second player from same tag');
|
||||||
|
assert.equal(warnLogs.length, 0, 'no warn logs');
|
||||||
|
|
||||||
|
const playerAgainWithOptions = videojs('test_vid_id', { techOrder: ['techFaker'] });
|
||||||
|
|
||||||
|
assert.equal(player,
|
||||||
|
playerAgainWithOptions,
|
||||||
|
'did not create a second player from same tag');
|
||||||
|
assert.equal(warnLogs.length, 1, 'logged a warning');
|
||||||
|
assert.equal(warnLogs[0],
|
||||||
|
'Player "test_vid_id" is already initialised. Options will not be applied.',
|
||||||
|
'logged the right message');
|
||||||
|
|
||||||
|
log.warn = origWarnLog;
|
||||||
|
|
||||||
|
player.dispose();
|
||||||
|
});
|
||||||
|
|
||||||
QUnit.test('should return a video player instance from el html5 tech', function(assert) {
|
QUnit.test('should return a video player instance from el html5 tech', function(assert) {
|
||||||
const fixture = document.getElementById('qunit-fixture');
|
const fixture = document.getElementById('qunit-fixture');
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user