From ed20e59ba16071fd1498728eac01bbbdd889b865 Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Tue, 5 Feb 2019 10:32:04 -0500 Subject: [PATCH] Test that setting a plugin to false in corePlugins disables it --- __tests__/configurePlugins.test.js | 35 ++++++++++++++++++++++++++++++ src/util/configurePlugins.js | 7 ++++++ 2 files changed, 42 insertions(+) create mode 100644 __tests__/configurePlugins.test.js create mode 100644 src/util/configurePlugins.js diff --git a/__tests__/configurePlugins.test.js b/__tests__/configurePlugins.test.js new file mode 100644 index 000000000..89896f8a8 --- /dev/null +++ b/__tests__/configurePlugins.test.js @@ -0,0 +1,35 @@ +import configurePlugins from '../src/util/configurePlugins' + +test('setting a plugin to false removes it', () => { + const plugins = { + fontSize: (options) => { + return { + plugin: 'fontSize', + options, + } + }, + display: (options) => { + return { + plugin: 'display', + options, + } + }, + backgroundPosition: (options) => { + return { + plugin: 'backgroundPosition', + options, + } + }, + } + + const configuredPlugins = configurePlugins(plugins, { + fontSize: {}, + display: false, + backgroundPosition: {}, + }) + + expect(configuredPlugins).toEqual([ + { plugin: 'fontSize', options: {} }, + { plugin: 'backgroundPosition', options: {} }, + ]) +}) diff --git a/src/util/configurePlugins.js b/src/util/configurePlugins.js new file mode 100644 index 000000000..0874d93a5 --- /dev/null +++ b/src/util/configurePlugins.js @@ -0,0 +1,7 @@ +export default function(plugins, pluginConfig) { + return Object.keys(plugins).filter(pluginName => { + return pluginConfig[pluginName] !== false + }).map(pluginName => { + return plugins[pluginName](pluginConfig[pluginName]) + }) +}