mirror of
https://github.com/videojs/video.js.git
synced 2025-07-17 01:42:41 +02:00
fix: copy basic plugin properties onto the wrapper (#4100)
Copy basic plugin properties to prevent breaking older basic plugins.
This commit is contained in:
committed by
Gary Katsevman
parent
405b29b8f1
commit
127cd7827e
@ -88,7 +88,8 @@ const markPluginAsActive = (player, name) => {
|
||||
* @returns {Function}
|
||||
* A wrapper function for the given plugin.
|
||||
*/
|
||||
const createBasicPlugin = (name, plugin) => function() {
|
||||
const createBasicPlugin = function(name, plugin) {
|
||||
const basicPluginWrapper = function() {
|
||||
const instance = plugin.apply(this, arguments);
|
||||
|
||||
markPluginAsActive(this, name);
|
||||
@ -101,6 +102,13 @@ const createBasicPlugin = (name, plugin) => function() {
|
||||
return instance;
|
||||
};
|
||||
|
||||
Object.keys(plugin).forEach(function(prop) {
|
||||
basicPluginWrapper[prop] = plugin[prop];
|
||||
});
|
||||
|
||||
return basicPluginWrapper;
|
||||
};
|
||||
|
||||
/**
|
||||
* Takes a plugin sub-class and returns a factory function for generating
|
||||
* instances of it.
|
||||
|
@ -38,6 +38,13 @@ QUnit.test('setup', function(assert) {
|
||||
assert.deepEqual(this.basic.firstCall.args, [{foo: 'bar'}, 123], 'the plugin had the correct arguments');
|
||||
assert.ok(this.player.usingPlugin('basic'), 'the player now recognizes that the plugin was set up');
|
||||
assert.ok(this.player.hasPlugin('basic'), 'player has the plugin available');
|
||||
|
||||
this.player.basic({foo: 'bar'}, 123);
|
||||
assert.strictEqual(this.basic.callCount, 2, 'the plugin was called twice');
|
||||
assert.strictEqual(this.basic.firstCall.thisValue, this.player, 'the plugin `this` value was the player');
|
||||
assert.deepEqual(this.basic.firstCall.args, [{foo: 'bar'}, 123], 'the plugin had the correct arguments');
|
||||
assert.ok(this.player.usingPlugin('basic'), 'the player now recognizes that the plugin was set up');
|
||||
assert.ok(this.player.hasPlugin('basic'), 'player has the plugin available');
|
||||
});
|
||||
|
||||
QUnit.test('"pluginsetup" event', function(assert) {
|
||||
@ -58,3 +65,20 @@ QUnit.test('"pluginsetup" event', function(assert) {
|
||||
plugin: this.basic
|
||||
}, 'the event hash object is correct');
|
||||
});
|
||||
|
||||
QUnit.test('properties are copied', function(assert) {
|
||||
const foo = () => {};
|
||||
|
||||
foo.someProp = () => {};
|
||||
foo.VERSION = '9.9.9';
|
||||
|
||||
Plugin.registerPlugin('foo', foo);
|
||||
|
||||
assert.strictEqual(this.player.foo.VERSION, foo.VERSION, 'properties are copied');
|
||||
assert.strictEqual(this.player.foo.someProp, foo.someProp, 'properties are copied');
|
||||
|
||||
this.player.foo();
|
||||
|
||||
assert.strictEqual(this.player.foo.VERSION, foo.VERSION, 'properties still exist after init');
|
||||
assert.strictEqual(this.player.foo.someProp, foo.someProp, 'properties still exist after init');
|
||||
});
|
||||
|
Reference in New Issue
Block a user