forked from robksawyer/tailwindcss-pixel-dimensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
230 lines (196 loc) · 5.42 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
const _ = require('lodash')
const postcss = require('postcss')
const tailwindcss = require('tailwindcss')
const plugin = require('./index.js')
const spacing = {
missing: ['.max-w-10px', '.min-h-10px', '.min-w-10px'],
results: [
'.bottom-10px',
'.gap-10px',
'.gap-x-10px',
'.gap-y-10px',
'.h-10px',
'.inset-10px',
'.inset-x-10px',
'.inset-y-10px',
'.left-10px',
'.m-10px',
'.max-h-10px',
'.mb-10px',
'.ml-10px',
'.mr-10px',
'.mt-10px',
'.mx-10px',
'.my-10px',
'.p-10px',
'.pb-10px',
'.pl-10px',
'.pr-10px',
'.pt-10px',
'.px-10px',
'.py-10px',
'.right-10px',
'.space-x-10px',
'.space-y-10px',
'.top-10px',
'.translate-x-10px',
'.translate-y-10px',
'.w-10px',
],
}
const generatePluginCss = (safelist, pluginOptions = {}) => {
const list = []
const keys = Object.keys(pluginOptions)
const count = keys.length
if (count > 0) {
list.push(plugin(pluginOptions))
}
return postcss(
tailwindcss({
safelist,
plugins: list,
})
).process('@tailwind components; @tailwind utilities', {
from: undefined,
})
}
test('900 values (+1) are generated by default... [ width ]', () => {
return generatePluginCss(['w-0px', 'w-900px'], { width: {} }).then(
({ css }) => {
const list = css.match(/\.w-[0-9][0-9]*px/g)
expect(list).toEqual(expect.arrayContaining(['.w-0px', '.w-900px']))
}
)
})
test('900 values (+1) are generated by default... [ height ]', () => {
return generatePluginCss(['h-0px', 'h-900px'], { height: {} }).then(
({ css }) => {
const list = css.match(/\.h-[0-9][0-9]*px/g)
expect(list).toEqual(expect.arrayContaining(['.h-0px', '.h-900px']))
}
)
})
// Note: If the results contain a backslash, add another to escape it.
test('A single value (+1) can be added... [ width ]', () => {
const results = ['.w-0px', '.w-1px']
const invalid = ['.h-2px']
const safelist = [...results, ...invalid]
return generatePluginCss(safelist, {
width: {
stop: 1,
},
}).then(({ css }) => {
const list = css.match(/\.w-[01]px/g)
expect(list).toEqual(expect.arrayContaining(results))
expect(list).not.toEqual(expect.arrayContaining(invalid))
})
})
test('A range of values can be added... [ width ]', () => {
const results = ['.w-30px', '.w-31px', '.w-40px']
const invalid = ['.w-20px', '.w-44px']
const safelist = [...results, ...invalid]
return generatePluginCss(safelist, {
width: {
stop: 40,
start: 30,
},
}).then(({ css }) => {
const list = css.match(/\.w-[34][0-9]px/g)
expect(list).toEqual(expect.arrayContaining(results))
expect(list).not.toEqual(expect.arrayContaining(invalid))
})
})
test('A single value can be added... [ width ]', () => {
const results = ['.w-40px']
const invalid = ['.w-39px', '.w-41px']
const safelist = [...results, ...invalid]
return generatePluginCss(safelist, {
width: {
stop: 40,
start: 40,
},
}).then(({ css }) => {
const list = css.match(/\.w-[34][0-9]px/g)
expect(list).toEqual(expect.arrayContaining(results))
expect(list).not.toEqual(expect.arrayContaining(invalid))
})
})
test('Supports the old option properties... [ width ]', () => {
const results = ['.w-30px', '.w-31px', '.w-40px']
return generatePluginCss(results, {
width: {
total: 40,
startingValue: 30,
},
}).then(({ css }) => {
const list = css.match(/\.w-[34][0-9]px/g)
expect(list).toEqual(expect.arrayContaining(results))
})
})
test('Multiple values can be added... [ spacing ]', () => {
const results = [...spacing.results]
return generatePluginCss(results, {
spacing: {
stop: 10,
},
}).then(({ css }) => {
const list = css.match(/\..*-*.*-*.*-10px/g)
// NOTE: it's ODD that only .max-h-10px gets generated
// (no other min / max values)
expect(list).toEqual(expect.arrayContaining(results))
// expect(list.length).toEqual(results.length)
})
})
test('Multiple values can be added... [ spacing + max/min ]', () => {
const results = [...spacing.results, ...spacing.missing]
return generatePluginCss(results, {
spacing: {
stop: 10,
},
maxWidth: {
stop: 10,
},
minWidth: {
stop: 10,
},
minHeight: {
stop: 10,
},
}).then(({ css }) => {
const list = css.match(/\..*-*.*-*.*-10px/g)
expect(list).toEqual(expect.arrayContaining(results))
})
})
test('Multiple values can be added... [ maxWidth ]', () => {
const results = ['.max-w-0px', '.max-w-10px']
return generatePluginCss(results, {
maxWidth: {
stop: 10,
},
}).then(({ css }) => {
const list = css.match(/\.max-w-[0-9][0-9]*px/g)
expect(list).toEqual(expect.arrayContaining(results))
})
})
test('Multiple values can be added... [ fontSize ]', () => {
const results = ['.text-0px', '.text-10px']
return generatePluginCss(results, {
fontSize: {
stop: 10,
},
}).then(({ css }) => {
const list = css.match(/\.text-[0-9][0-9]*px/g)
expect(list).toEqual(expect.arrayContaining(results))
})
})
test('Multiple values can be added... [ lineHeight ]', () => {
const results = ['.leading-0px', '.leading-10px']
return generatePluginCss(results, {
lineHeight: {
stop: 10,
},
}).then(({ css }) => {
const list = css.match(/\.leading-[0-9][0-9]*px/g)
expect(list).toEqual(expect.arrayContaining(results))
})
})