Skip to content

Commit 593b2d0

Browse files
committed
Add helper for testing utility plugins
1 parent 50569de commit 593b2d0

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import _ from 'lodash'
2+
import escapeClassName from '../../../src/util/escapeClassName'
3+
4+
export default function(plugin, config) {
5+
const addedUtilities = []
6+
7+
const getConfigValue = (path, defaultValue) => _.get(config, path, defaultValue)
8+
const pluginApi = {
9+
config: getConfigValue,
10+
e: escapeClassName,
11+
theme: (path, defaultValue) => getConfigValue(`theme.${path}`, defaultValue),
12+
variants: (path, defaultValue) => {
13+
if (_.isArray(config.variants)) {
14+
return config.variants
15+
}
16+
17+
return getConfigValue(`variants.${path}`, defaultValue)
18+
},
19+
addUtilities(utilities, variants) {
20+
addedUtilities.push([utilities, variants])
21+
},
22+
}
23+
24+
plugin(pluginApi)
25+
26+
return {
27+
utilities: addedUtilities,
28+
}
29+
}

0 commit comments

Comments
 (0)