diff --git a/src/microplugin.js b/src/microplugin.js index 0b53c50..7138722 100644 --- a/src/microplugin.js +++ b/src/microplugin.js @@ -48,7 +48,7 @@ var self = this; var queue = []; - self.plugins = { + self.plugins = self.plugins || { names : [], settings : {}, requested : {}, diff --git a/test/index.js b/test/index.js index 84254f7..3f5df33 100644 --- a/test/index.js +++ b/test/index.js @@ -169,6 +169,23 @@ describe('MicroPlugin', function() { }); + it('should not overwrite `plugins` data from previous initializations', function() { + var Lib = function() { + this.initializePlugins({'a': {test: 'hello_a'}}); + this.initializePlugins(['b']); + }; + MicroPlugin.mixin(Lib); + + Lib.define('a', function () { }); + Lib.define('b', function () { }); + + var instance = new Lib(); + assert(instance.plugins.names.indexOf('a') >= 0); + assert.deepEqual(instance.plugins.settings['a'], {test: 'hello_a'}); + assert(instance.plugins.requested['a']); + assert(instance.plugins.loaded.hasOwnProperty('a')); + }); + }); describe('#require()', function() {