From 67106e86981852d2d55830a8fca494c7d33eff37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Tue, 7 Jun 2016 11:06:53 +0200 Subject: [PATCH] Improve plugins config modifier --- .../config/__tests__/removePlugin.js | 33 +++++++++++++++++++ lib/modifiers/config/hasPlugin.js | 15 +++++++++ lib/modifiers/config/index.js | 10 +++--- lib/modifiers/config/isDefaultPlugin.js | 5 ++- lib/modifiers/config/removePlugin.js | 2 +- lib/modifiers/config/togglePlugin.js | 14 ++++++-- testing/setup.js | 28 +++++++++++----- 7 files changed, 87 insertions(+), 20 deletions(-) create mode 100644 lib/modifiers/config/__tests__/removePlugin.js create mode 100644 lib/modifiers/config/hasPlugin.js diff --git a/lib/modifiers/config/__tests__/removePlugin.js b/lib/modifiers/config/__tests__/removePlugin.js new file mode 100644 index 000000000..253cc397f --- /dev/null +++ b/lib/modifiers/config/__tests__/removePlugin.js @@ -0,0 +1,33 @@ +var removePlugin = require('../removePlugin'); +var Config = require('../../../models/config'); + +describe('removePlugin', function() { + var config = Config.createWithValues({ + plugins: ['hello', 'world', '-disabled'] + }); + + it('should remove the plugin from the list', function() { + var newConfig = removePlugin(config, 'hello'); + + var testDep = newConfig.getPluginDependency('hello'); + expect(testDep).toNotBeDefined(); + }); + + it('should remove the disabled plugin from the list', function() { + var newConfig = removePlugin(config, 'disabled'); + + var testDep = newConfig.getPluginDependency('disabled'); + expect(testDep).toNotBeDefined(); + }); + + it('should disable default plugin', function() { + var newConfig = removePlugin(config, 'search'); + + var disabledDep = newConfig.getPluginDependency('search'); + expect(disabledDep).toBeDefined(); + expect(disabledDep.getVersion()).toEqual('*'); + expect(disabledDep.isEnabled()).toBeFalsy(); + }); +}); + + diff --git a/lib/modifiers/config/hasPlugin.js b/lib/modifiers/config/hasPlugin.js new file mode 100644 index 000000000..9aab4f29d --- /dev/null +++ b/lib/modifiers/config/hasPlugin.js @@ -0,0 +1,15 @@ + +/** + * Test if a plugin is listed + * @param { {List