File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed
Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -1766,6 +1766,55 @@ test('plugins with extra options can be created using the `createPlugin.withOpti
17661766 } )
17671767} )
17681768
1769+ test ( 'plugins should cache correctly' , ( ) => {
1770+ const plugin = createPlugin . withOptions (
1771+ ( { className = 'banana' } = { } ) => ( { addComponents, variants } ) => {
1772+ addComponents ( { [ `.${ className } ` ] : { position : 'absolute' } } , variants ( 'testPlugin' ) )
1773+ } ,
1774+ ( ) => ( { variants : { testPlugin : [ 'responsive' ] } } )
1775+ )
1776+
1777+ function run ( options = { } ) {
1778+ return _postcss ( [
1779+ tailwind ( {
1780+ corePlugins : [ ] ,
1781+ theme : { screens : { sm : '400px' } } ,
1782+ plugins : [ plugin ( options ) ] ,
1783+ } ) ,
1784+ ] ) . process ( `@tailwind base; @tailwind components; @tailwind utilities;` , {
1785+ from : undefined ,
1786+ } )
1787+ }
1788+
1789+ return Promise . all ( [ run ( ) , run ( { className : 'apple' } ) ] ) . then ( ( [ result1 , result2 ] ) => {
1790+ const expected1 = `
1791+ .banana {
1792+ position: absolute;
1793+ }
1794+
1795+ @media (min-width: 400px) {
1796+ .sm\\:banana {
1797+ position: absolute;
1798+ }
1799+ }
1800+ `
1801+
1802+ const expected2 = `
1803+ .apple {
1804+ position: absolute;
1805+ }
1806+
1807+ @media (min-width: 400px) {
1808+ .sm\\:apple {
1809+ position: absolute;
1810+ }
1811+ }
1812+ `
1813+ expect ( result1 . css ) . toMatchCss ( expected1 )
1814+ expect ( result2 . css ) . toMatchCss ( expected2 )
1815+ } )
1816+ } )
1817+
17691818test ( 'plugins created using `createPlugin.withOptions` do not need to be invoked if the user wants to use the default options' , ( ) => {
17701819 const plugin = createPlugin . withOptions (
17711820 function ( { className } = { className : 'banana' } ) {
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ function createPlugin(plugin, config) {
88createPlugin . withOptions = function ( pluginFunction , configFunction = ( ) => ( { } ) ) {
99 const optionsFunction = function ( options ) {
1010 return {
11+ __options : options ,
1112 handler : pluginFunction ( options ) ,
1213 config : configFunction ( options ) ,
1314 }
You can’t perform that action at this time.
0 commit comments