Skip to content

Commit b3a7f77

Browse files
committed
Test making config function optional, refactor to default parameter
1 parent ac21390 commit b3a7f77

File tree

2 files changed

+87
-2
lines changed

2 files changed

+87
-2
lines changed

__tests__/processPlugins.test.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,3 +1570,88 @@ test('plugins created using `createPlugin.withOptions` do not need to be invoked
15701570
expect(result.css).toMatchCss(expected)
15711571
})
15721572
})
1573+
1574+
test('the configFunction parameter is optional when using the `createPlugin.withOptions` function', () => {
1575+
const plugin = createPlugin.withOptions(function({ className }) {
1576+
return function({ addUtilities, theme, variants }) {
1577+
const utilities = _.fromPairs(
1578+
_.toPairs(theme('testPlugin')).map(([k, v]) => [`.${className}-${k}`, { testProperty: v }])
1579+
)
1580+
1581+
addUtilities(utilities, variants('testPlugin'))
1582+
}
1583+
})
1584+
1585+
return _postcss([
1586+
tailwind({
1587+
corePlugins: [],
1588+
theme: {
1589+
screens: {
1590+
sm: '400px',
1591+
},
1592+
testPlugin: {
1593+
sm: '1px',
1594+
md: '2px',
1595+
lg: '3px',
1596+
},
1597+
},
1598+
variants: {
1599+
testPlugin: ['responsive', 'focus'],
1600+
},
1601+
plugins: [plugin({ className: 'banana' })],
1602+
}),
1603+
])
1604+
.process(
1605+
`
1606+
@tailwind base;
1607+
@tailwind components;
1608+
@tailwind utilities;
1609+
`,
1610+
{ from: undefined }
1611+
)
1612+
.then(result => {
1613+
const expected = `
1614+
.banana-sm {
1615+
test-property: 1px
1616+
}
1617+
.banana-md {
1618+
test-property: 2px
1619+
}
1620+
.banana-lg {
1621+
test-property: 3px
1622+
}
1623+
.focus\\:banana-sm:focus {
1624+
test-property: 1px
1625+
}
1626+
.focus\\:banana-md:focus {
1627+
test-property: 2px
1628+
}
1629+
.focus\\:banana-lg:focus {
1630+
test-property: 3px
1631+
}
1632+
1633+
@media (min-width: 400px) {
1634+
.sm\\:banana-sm {
1635+
test-property: 1px
1636+
}
1637+
.sm\\:banana-md {
1638+
test-property: 2px
1639+
}
1640+
.sm\\:banana-lg {
1641+
test-property: 3px
1642+
}
1643+
.sm\\:focus\\:banana-sm:focus {
1644+
test-property: 1px
1645+
}
1646+
.sm\\:focus\\:banana-md:focus {
1647+
test-property: 2px
1648+
}
1649+
.sm\\:focus\\:banana-lg:focus {
1650+
test-property: 3px
1651+
}
1652+
}
1653+
`
1654+
1655+
expect(result.css).toMatchCss(expected)
1656+
})
1657+
})

src/util/createPlugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ function createPlugin(plugin, config) {
55
}
66
}
77

8-
createPlugin.withOptions = function(pluginFunction, configFunction) {
8+
createPlugin.withOptions = function(pluginFunction, configFunction = () => ({})) {
99
const optionsFunction = function(options) {
1010
return {
1111
handler: pluginFunction(options),
12-
config: configFunction ? configFunction(options) : {},
12+
config: configFunction(options),
1313
}
1414
}
1515

0 commit comments

Comments
 (0)