|
| 1 | +const tailwindConfig = require('./tailwind.config.js') |
| 2 | +const { generatePluginCss } = require('@hacknug/tailwindcss-plugin-utils') |
| 3 | + |
| 4 | +expect.extend({ toMatchCss: require('jest-matcher-css') }) |
| 5 | + |
| 6 | +const commonConfig = { |
| 7 | + theme: { |
| 8 | + screens: { 'sm': '640px' }, |
| 9 | + colors: { |
| 10 | + transparent: 'transparent', |
| 11 | + black: '#000', |
| 12 | + white: '#fff', |
| 13 | + gray: { |
| 14 | + '100': '#f5f5f5', |
| 15 | + '200': '#eeeeee', |
| 16 | + '300': '#e0e0e0', |
| 17 | + '400': '#bdbdbd', |
| 18 | + '500': '#9e9e9e', |
| 19 | + '600': '#757575', |
| 20 | + '700': '#616161', |
| 21 | + '800': '#424242', |
| 22 | + '900': '#212121', |
| 23 | + }, |
| 24 | + }, |
| 25 | + }, |
| 26 | + corePlugins: false, |
| 27 | +} |
| 28 | + |
| 29 | +test('generates default utilities', () => { |
| 30 | + const testConfig = { ...commonConfig } |
| 31 | + const expectedCss = ` |
| 32 | + .text-fill-transparent { -webkit-text-fill-color: transparent } |
| 33 | + .text-fill-black { -webkit-text-fill-color: #000 } |
| 34 | + .text-fill-white { -webkit-text-fill-color: #fff } |
| 35 | + .text-fill-gray-100 { -webkit-text-fill-color: #f5f5f5 } |
| 36 | + .text-fill-gray-200 { -webkit-text-fill-color: #eeeeee } |
| 37 | + .text-fill-gray-300 { -webkit-text-fill-color: #e0e0e0 } |
| 38 | + .text-fill-gray-400 { -webkit-text-fill-color: #bdbdbd } |
| 39 | + .text-fill-gray-500 { -webkit-text-fill-color: #9e9e9e } |
| 40 | + .text-fill-gray-600 { -webkit-text-fill-color: #757575 } |
| 41 | + .text-fill-gray-700 { -webkit-text-fill-color: #616161 } |
| 42 | + .text-fill-gray-800 { -webkit-text-fill-color: #424242 } |
| 43 | + .text-fill-gray-900 { -webkit-text-fill-color: #212121 } |
| 44 | + .text-fill { -webkit-text-fill-color: #e0e0e0 } |
| 45 | +
|
| 46 | + .text-stroke-transparent { -webkit-text-stroke-color: transparent } |
| 47 | + .text-stroke-black { -webkit-text-stroke-color: #000 } |
| 48 | + .text-stroke-white { -webkit-text-stroke-color: #fff } |
| 49 | + .text-stroke-gray-100 { -webkit-text-stroke-color: #f5f5f5 } |
| 50 | + .text-stroke-gray-200 { -webkit-text-stroke-color: #eeeeee } |
| 51 | + .text-stroke-gray-300 { -webkit-text-stroke-color: #e0e0e0 } |
| 52 | + .text-stroke-gray-400 { -webkit-text-stroke-color: #bdbdbd } |
| 53 | + .text-stroke-gray-500 { -webkit-text-stroke-color: #9e9e9e } |
| 54 | + .text-stroke-gray-600 { -webkit-text-stroke-color: #757575 } |
| 55 | + .text-stroke-gray-700 { -webkit-text-stroke-color: #616161 } |
| 56 | + .text-stroke-gray-800 { -webkit-text-stroke-color: #424242 } |
| 57 | + .text-stroke-gray-900 { -webkit-text-stroke-color: #212121 } |
| 58 | + .text-stroke { -webkit-text-stroke-color: #e0e0e0 } |
| 59 | +
|
| 60 | + .text-stroke-0 { -webkit-text-stroke-width: 0 } |
| 61 | + .text-stroke-2 { -webkit-text-stroke-width: 2px } |
| 62 | + .text-stroke-4 { -webkit-text-stroke-width: 4px } |
| 63 | + .text-stroke-8 { -webkit-text-stroke-width: 8px } |
| 64 | + .text-stroke { -webkit-text-stroke-width: 1px } |
| 65 | +
|
| 66 | + .paint-fsm { paint-order: fill stroke markers } |
| 67 | + .paint-fms { paint-order: fill markers stroke } |
| 68 | + .paint-sfm { paint-order: stroke fill markers } |
| 69 | + .paint-smf { paint-order: stroke markers fill } |
| 70 | + .paint-mfs { paint-order: markers fill stroke } |
| 71 | + .paint-msf { paint-order: markers stroke fill } |
| 72 | + ` |
| 73 | + |
| 74 | + return generatePluginCss(tailwindConfig, testConfig).then(css => expect(css).toMatchCss(expectedCss)) |
| 75 | +}) |
| 76 | + |
| 77 | +test('variants can be customized', () => { |
| 78 | + const testConfig = { |
| 79 | + ...commonConfig, |
| 80 | + variants: { |
| 81 | + textFillColor: ['hover'], |
| 82 | + textStrokeColor: ['focus'], |
| 83 | + textStrokeWidth: ['active'], |
| 84 | + paintOrder: ['responsive', 'hover'], |
| 85 | + }, |
| 86 | + } |
| 87 | + const expectedCss = ` |
| 88 | + .text-fill-transparent { -webkit-text-fill-color: transparent } |
| 89 | + .text-fill-black { -webkit-text-fill-color: #000 } |
| 90 | + .text-fill-white { -webkit-text-fill-color: #fff } |
| 91 | + .text-fill-gray-100 { -webkit-text-fill-color: #f5f5f5 } |
| 92 | + .text-fill-gray-200 { -webkit-text-fill-color: #eeeeee } |
| 93 | + .text-fill-gray-300 { -webkit-text-fill-color: #e0e0e0 } |
| 94 | + .text-fill-gray-400 { -webkit-text-fill-color: #bdbdbd } |
| 95 | + .text-fill-gray-500 { -webkit-text-fill-color: #9e9e9e } |
| 96 | + .text-fill-gray-600 { -webkit-text-fill-color: #757575 } |
| 97 | + .text-fill-gray-700 { -webkit-text-fill-color: #616161 } |
| 98 | + .text-fill-gray-800 { -webkit-text-fill-color: #424242 } |
| 99 | + .text-fill-gray-900 { -webkit-text-fill-color: #212121 } |
| 100 | + .text-fill { -webkit-text-fill-color: #e0e0e0 } |
| 101 | +
|
| 102 | + .hover\\:text-fill-transparent:hover { -webkit-text-fill-color: transparent } |
| 103 | + .hover\\:text-fill-black:hover { -webkit-text-fill-color: #000 } |
| 104 | + .hover\\:text-fill-white:hover { -webkit-text-fill-color: #fff } |
| 105 | + .hover\\:text-fill-gray-100:hover { -webkit-text-fill-color: #f5f5f5 } |
| 106 | + .hover\\:text-fill-gray-200:hover { -webkit-text-fill-color: #eeeeee } |
| 107 | + .hover\\:text-fill-gray-300:hover { -webkit-text-fill-color: #e0e0e0 } |
| 108 | + .hover\\:text-fill-gray-400:hover { -webkit-text-fill-color: #bdbdbd } |
| 109 | + .hover\\:text-fill-gray-500:hover { -webkit-text-fill-color: #9e9e9e } |
| 110 | + .hover\\:text-fill-gray-600:hover { -webkit-text-fill-color: #757575 } |
| 111 | + .hover\\:text-fill-gray-700:hover { -webkit-text-fill-color: #616161 } |
| 112 | + .hover\\:text-fill-gray-800:hover { -webkit-text-fill-color: #424242 } |
| 113 | + .hover\\:text-fill-gray-900:hover { -webkit-text-fill-color: #212121 } |
| 114 | + .hover\\:text-fill:hover { -webkit-text-fill-color: #e0e0e0 } |
| 115 | +
|
| 116 | + .text-stroke-transparent { -webkit-text-stroke-color: transparent } |
| 117 | + .text-stroke-black { -webkit-text-stroke-color: #000 } |
| 118 | + .text-stroke-white { -webkit-text-stroke-color: #fff } |
| 119 | + .text-stroke-gray-100 { -webkit-text-stroke-color: #f5f5f5 } |
| 120 | + .text-stroke-gray-200 { -webkit-text-stroke-color: #eeeeee } |
| 121 | + .text-stroke-gray-300 { -webkit-text-stroke-color: #e0e0e0 } |
| 122 | + .text-stroke-gray-400 { -webkit-text-stroke-color: #bdbdbd } |
| 123 | + .text-stroke-gray-500 { -webkit-text-stroke-color: #9e9e9e } |
| 124 | + .text-stroke-gray-600 { -webkit-text-stroke-color: #757575 } |
| 125 | + .text-stroke-gray-700 { -webkit-text-stroke-color: #616161 } |
| 126 | + .text-stroke-gray-800 { -webkit-text-stroke-color: #424242 } |
| 127 | + .text-stroke-gray-900 { -webkit-text-stroke-color: #212121 } |
| 128 | + .text-stroke { -webkit-text-stroke-color: #e0e0e0 } |
| 129 | +
|
| 130 | + .focus\\:text-stroke-transparent:focus { -webkit-text-stroke-color: transparent } |
| 131 | + .focus\\:text-stroke-black:focus { -webkit-text-stroke-color: #000 } |
| 132 | + .focus\\:text-stroke-white:focus { -webkit-text-stroke-color: #fff } |
| 133 | + .focus\\:text-stroke-gray-100:focus { -webkit-text-stroke-color: #f5f5f5 } |
| 134 | + .focus\\:text-stroke-gray-200:focus { -webkit-text-stroke-color: #eeeeee } |
| 135 | + .focus\\:text-stroke-gray-300:focus { -webkit-text-stroke-color: #e0e0e0 } |
| 136 | + .focus\\:text-stroke-gray-400:focus { -webkit-text-stroke-color: #bdbdbd } |
| 137 | + .focus\\:text-stroke-gray-500:focus { -webkit-text-stroke-color: #9e9e9e } |
| 138 | + .focus\\:text-stroke-gray-600:focus { -webkit-text-stroke-color: #757575 } |
| 139 | + .focus\\:text-stroke-gray-700:focus { -webkit-text-stroke-color: #616161 } |
| 140 | + .focus\\:text-stroke-gray-800:focus { -webkit-text-stroke-color: #424242 } |
| 141 | + .focus\\:text-stroke-gray-900:focus { -webkit-text-stroke-color: #212121 } |
| 142 | + .focus\\:text-stroke:focus { -webkit-text-stroke-color: #e0e0e0 } |
| 143 | +
|
| 144 | + .text-stroke-0 { -webkit-text-stroke-width: 0 } |
| 145 | + .text-stroke-2 { -webkit-text-stroke-width: 2px } |
| 146 | + .text-stroke-4 { -webkit-text-stroke-width: 4px } |
| 147 | + .text-stroke-8 { -webkit-text-stroke-width: 8px } |
| 148 | + .text-stroke { -webkit-text-stroke-width: 1px } |
| 149 | +
|
| 150 | + .active\\:text-stroke-0:active { -webkit-text-stroke-width: 0 } |
| 151 | + .active\\:text-stroke-2:active { -webkit-text-stroke-width: 2px } |
| 152 | + .active\\:text-stroke-4:active { -webkit-text-stroke-width: 4px } |
| 153 | + .active\\:text-stroke-8:active { -webkit-text-stroke-width: 8px } |
| 154 | + .active\\:text-stroke:active { -webkit-text-stroke-width: 1px } |
| 155 | +
|
| 156 | + .paint-fsm { paint-order: fill stroke markers } |
| 157 | + .paint-fms { paint-order: fill markers stroke } |
| 158 | + .paint-sfm { paint-order: stroke fill markers } |
| 159 | + .paint-smf { paint-order: stroke markers fill } |
| 160 | + .paint-mfs { paint-order: markers fill stroke } |
| 161 | + .paint-msf { paint-order: markers stroke fill } |
| 162 | +
|
| 163 | + .hover\\:paint-fsm:hover { paint-order: fill stroke markers } |
| 164 | + .hover\\:paint-fms:hover { paint-order: fill markers stroke } |
| 165 | + .hover\\:paint-sfm:hover { paint-order: stroke fill markers } |
| 166 | + .hover\\:paint-smf:hover { paint-order: stroke markers fill } |
| 167 | + .hover\\:paint-mfs:hover { paint-order: markers fill stroke } |
| 168 | + .hover\\:paint-msf:hover { paint-order: markers stroke fill } |
| 169 | +
|
| 170 | + @media (min-width: 640px) { |
| 171 | + .sm\\:paint-fsm { paint-order: fill stroke markers } |
| 172 | + .sm\\:paint-fms { paint-order: fill markers stroke } |
| 173 | + .sm\\:paint-sfm { paint-order: stroke fill markers } |
| 174 | + .sm\\:paint-smf { paint-order: stroke markers fill } |
| 175 | + .sm\\:paint-mfs { paint-order: markers fill stroke } |
| 176 | + .sm\\:paint-msf { paint-order: markers stroke fill } |
| 177 | +
|
| 178 | + .sm\\:hover\\:paint-fsm:hover { paint-order: fill stroke markers } |
| 179 | + .sm\\:hover\\:paint-fms:hover { paint-order: fill markers stroke } |
| 180 | + .sm\\:hover\\:paint-sfm:hover { paint-order: stroke fill markers } |
| 181 | + .sm\\:hover\\:paint-smf:hover { paint-order: stroke markers fill } |
| 182 | + .sm\\:hover\\:paint-mfs:hover { paint-order: markers fill stroke } |
| 183 | + .sm\\:hover\\:paint-msf:hover { paint-order: markers stroke fill } |
| 184 | + } |
| 185 | + ` |
| 186 | + |
| 187 | + return generatePluginCss(tailwindConfig, testConfig).then(css => expect(css).toMatchCss(expectedCss)) |
| 188 | +}) |
| 189 | + |
| 190 | + |
| 191 | +test('utilities can be customized', () => { |
| 192 | + const testConfig = { |
| 193 | + theme: { |
| 194 | + textFillColor: theme => ({ |
| 195 | + transparent: 'transparent', |
| 196 | + black: '#000', |
| 197 | + white: '#fff', |
| 198 | + gray: '#9e9e9e', |
| 199 | + default: '#38b2ac', |
| 200 | + }), |
| 201 | + textStrokeColor: theme => ({ |
| 202 | + transparent: theme('colors.transparent'), |
| 203 | + default: '#38b2ac' |
| 204 | + }), |
| 205 | + textStrokeWidth: { default: '1px', sm: '2px', md: '4px', lg: '8px' }, |
| 206 | + paintOrder: { stroke: 'stroke' } |
| 207 | + }, |
| 208 | + } |
| 209 | + const expectedCss = ` |
| 210 | + .text-fill-transparent { -webkit-text-fill-color: transparent } |
| 211 | + .text-fill-black { -webkit-text-fill-color: #000 } |
| 212 | + .text-fill-white { -webkit-text-fill-color: #fff } |
| 213 | + .text-fill-gray { -webkit-text-fill-color: #9e9e9e } |
| 214 | + .text-fill { -webkit-text-fill-color: #38b2ac } |
| 215 | +
|
| 216 | + .text-stroke-transparent { -webkit-text-stroke-color: transparent } |
| 217 | + .text-stroke { -webkit-text-stroke-color: #38b2ac } |
| 218 | +
|
| 219 | + .text-stroke { -webkit-text-stroke-width: 1px } |
| 220 | + .text-stroke-sm { -webkit-text-stroke-width: 2px } |
| 221 | + .text-stroke-md { -webkit-text-stroke-width: 4px } |
| 222 | + .text-stroke-lg { -webkit-text-stroke-width: 8px } |
| 223 | +
|
| 224 | + ${ /* FIXME: Merging of configs not working */'' } |
| 225 | + .paint-fsm { paint-order: fill stroke markers } |
| 226 | + .paint-fms { paint-order: fill markers stroke } |
| 227 | + .paint-sfm { paint-order: stroke fill markers } |
| 228 | + .paint-smf { paint-order: stroke markers fill } |
| 229 | + .paint-mfs { paint-order: markers fill stroke } |
| 230 | + .paint-msf { paint-order: markers stroke fill } |
| 231 | +
|
| 232 | + .paint-stroke { paint-order: stroke } |
| 233 | + ` |
| 234 | + |
| 235 | + return generatePluginCss(tailwindConfig, testConfig).then(css => expect(css).toMatchCss(expectedCss)) |
| 236 | +}) |
0 commit comments