Skip to content

Commit

Permalink
Log an error when a plugin can't be found
Browse files Browse the repository at this point in the history
closes #1931
closes #1928
  • Loading branch information
thijstriemstra authored and heff committed Jul 8, 2015
1 parent 49fbea6 commit 56be47b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

--------------------

Expand Down
6 changes: 5 additions & 1 deletion src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
32 changes: 32 additions & 0 deletions test/unit/plugins.test.js
Original file line number Diff line number Diff line change
@@ -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');

Expand Down Expand Up @@ -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;
});

0 comments on commit 56be47b

Please sign in to comment.