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