From 56be47b80a06a17ec8fabcfff909e931b08fae1e Mon Sep 17 00:00:00 2001 From: Thijs Triemstra Date: Fri, 6 Mar 2015 01:53:00 +0100 Subject: [PATCH] Log an error when a plugin can't be found closes #1931 closes #1928 --- CHANGELOG.md | 1 + src/js/player.js | 6 +++++- test/unit/plugins.test.js | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12de16f9c3..8b08c869b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,7 @@ CHANGELOG * @pavelhoral fixed a bug with user activity that caused the control bar to flicker ([view](/~https://github.com/videojs/video.js/pull/2299)) * @dmlap updated to videojs-swf@4.7.1 to fix a video dimensions issue on subsequent loads ([view](/~https://github.com/videojs/video.js/pull/2281)) * @mmcc added the vjs-big-play-centered class ([view](/~https://github.com/videojs/video.js/pull/2293)) +* @thijstriemstra added a logged error when a plugin is missing ([view](/~https://github.com/videojs/video.js/pull/1931)) -------------------- diff --git a/src/js/player.js b/src/js/player.js index 7dfa4f6d46..c554561da5 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -154,7 +154,11 @@ class Player extends Component { Object.getOwnPropertyNames(plugins).forEach(function(name){ plugins[name].playerOptions = playerOptionsCopy; - this[name](plugins[name]); + if (typeof this[name] === 'function') { + this[name](plugins[name]); + } else { + log.error('Unable to find plugin:', name); + } }, this); } diff --git a/test/unit/plugins.test.js b/test/unit/plugins.test.js index c55e0b87c2..cc197bdedd 100644 --- a/test/unit/plugins.test.js +++ b/test/unit/plugins.test.js @@ -1,6 +1,7 @@ import Plugin from '../../src/js/plugins.js'; import Player from '../../src/js/player.js'; import TestHelpers from './test-helpers.js'; +import window from 'global/window'; q.module('Plugins'); @@ -166,3 +167,34 @@ test('Plugins should not get events after stopImmediatePropagation is called', f equal(order.length, 1, 'only one event listener should have triggered'); player.dispose(); }); + +test('Plugin that does not exist logs an error', function() { + // stub the global log functions + var console, log, error, origConsole; + origConsole = window['console']; + console = window['console'] = { + log: function(){}, + warn: function(){}, + error: function(){} + }; + log = sinon.stub(console, 'log'); + error = sinon.stub(console, 'error'); + + // enable a non-existing plugin + TestHelpers.makePlayer({ + plugins: { + 'nonExistingPlugin': { + 'foo': 'bar' + } + } + }); + + ok(error.called, 'error was called'); + equal(error.firstCall.args[2], 'Unable to find plugin:'); + equal(error.firstCall.args[3], 'nonExistingPlugin'); + + // tear down logging stubs + log.restore(); + error.restore(); + window['console'] = origConsole; +});