From 921e2ff2025e7f385cd0c24c1009bfc06b4ad8ef Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Thu, 16 Apr 2020 09:25:21 -0400 Subject: [PATCH] Add helper for testing utility plugins --- __tests__/plugins/util/invokePlugin.js | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 __tests__/plugins/util/invokePlugin.js diff --git a/__tests__/plugins/util/invokePlugin.js b/__tests__/plugins/util/invokePlugin.js new file mode 100644 index 000000000..df663a4c5 --- /dev/null +++ b/__tests__/plugins/util/invokePlugin.js @@ -0,0 +1,29 @@ +import _ from 'lodash' +import escapeClassName from '../../../src/util/escapeClassName' + +export default function(plugin, config) { + const addedUtilities = [] + + const getConfigValue = (path, defaultValue) => _.get(config, path, defaultValue) + const pluginApi = { + config: getConfigValue, + e: escapeClassName, + theme: (path, defaultValue) => getConfigValue(`theme.${path}`, defaultValue), + variants: (path, defaultValue) => { + if (_.isArray(config.variants)) { + return config.variants + } + + return getConfigValue(`variants.${path}`, defaultValue) + }, + addUtilities(utilities, variants) { + addedUtilities.push([utilities, variants]) + }, + } + + plugin(pluginApi) + + return { + utilities: addedUtilities, + } +}