diff --git a/src/js/plugin.js b/src/js/plugin.js index e01b70bc27..bd306a586f 100644 --- a/src/js/plugin.js +++ b/src/js/plugin.js @@ -5,6 +5,7 @@ import evented from './mixins/evented'; import stateful from './mixins/stateful'; import * as Events from './utils/events'; import * as Fn from './utils/fn'; +import log from './utils/log'; import Player from './player'; /** @@ -305,8 +306,10 @@ class Plugin { throw new Error(`Illegal plugin name, "${name}", must be a string, was ${typeof name}.`); } - if (pluginExists(name) || Player.prototype.hasOwnProperty(name)) { - throw new Error(`Illegal plugin name, "${name}", already exists.`); + if (pluginExists(name)) { + log.warn(`A plugin named "${name}" already exists. You may want to avoid re-registering plugins!`); + } else if (Player.prototype.hasOwnProperty(name)) { + throw new Error(`Illegal plugin name, "${name}", cannot share a name with an existing player method!`); } if (typeof plugin !== 'function') { diff --git a/test/unit/plugin-static.test.js b/test/unit/plugin-static.test.js index 02ca5bf1a7..e8a591bb94 100644 --- a/test/unit/plugin-static.test.js +++ b/test/unit/plugin-static.test.js @@ -1,4 +1,6 @@ /* eslint-env qunit */ +import sinon from 'sinon'; +import log from '../../src/js/utils/log'; import Player from '../../src/js/player'; import Plugin from '../../src/js/plugin'; @@ -53,12 +55,6 @@ QUnit.test('registerPlugin() illegal arguments', function(assert) { 'plugins must have a name' ); - assert.throws( - () => Plugin.registerPlugin('play'), - new Error('Illegal plugin name, "play", already exists.'), - 'plugins cannot share a name with an existing player method' - ); - assert.throws( () => Plugin.registerPlugin('foo'), new Error('Illegal plugin for "foo", must be a function, was undefined.'), @@ -70,6 +66,18 @@ QUnit.test('registerPlugin() illegal arguments', function(assert) { new Error('Illegal plugin for "foo", must be a function, was object.'), 'plugins must be functions' ); + + assert.throws( + () => Plugin.registerPlugin('play', function() {}), + new Error('Illegal plugin name, "play", cannot share a name with an existing player method!'), + 'plugins must be functions' + ); + + sinon.spy(log, 'warn'); + Plugin.registerPlugin('foo', function() {}); + Plugin.registerPlugin('foo', function() {}); + assert.strictEqual(log.warn.callCount, 1, 'warn on re-registering a plugin'); + log.warn.restore(); }); QUnit.test('getPlugin()', function(assert) {