-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
198 lines (167 loc) · 3.11 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
const _ = require('lodash')
const cssMatcher = require('jest-matcher-css')
const postcss = require('postcss')
const tailwindcss = require('tailwindcss')
/**
* generatePluginCss
* Handles generating base tailwind css
* @param {*} config
* @param {object} pluginOptions are the options passed to the plugin
* @return
*/
const generatePluginCss = (config, pluginOptions = {}) => {
return postcss(
tailwindcss(
_.merge(
{
theme: {
width: {},
height: {},
},
variants: [],
corePlugins: ['width', 'height'],
plugins: [require('./index.js')(pluginOptions)],
},
config
)
)
)
.process('@tailwind components; @tailwind utilities', {
from: undefined,
})
.then((result) => {
// console.log('results', result.css)
return result.css
})
}
/**
* Base display classes from TailwindCSS
* Note: I can't figure out how to get around these. If display
* is not added above to corePlugins, nothing shows up
*/
const baseCss = `
`
expect.extend({
toMatchCss: cssMatcher,
})
test('Nine hundred widths are generated by default', () => {
return generatePluginCss(null, {}).then((css) => {
expect(css).toMatch(/(w-900px)/)
})
})
test('Nine hundred heights are generated by default', () => {
return generatePluginCss(null, {}).then((css) => {
expect(css).toMatch(/(h-900px)/)
})
})
// Note: If the results contain a backslash, add another to escape it.
test('A single width and height can be added', () => {
return generatePluginCss(
{},
{
width: {
total: 1,
},
height: {
total: 1,
},
}
).then((css) => {
expect(css).toMatchCss(`
.w-0px {
width: 0;
}
.w-1px {
width: 1px;
}
.h-0px {
height: 0;
}
.h-1px {
height: 1px;
}
`)
})
})
test('Multiple widths and heights can be added', () => {
return generatePluginCss(
{},
{
width: {
total: 10,
},
height: {
total: 10,
},
}
).then((css) => {
expect(css).toMatchCss(`
.w-0px {
width: 0;
}
.w-1px {
width: 1px;
}
.w-2px {
width: 2px;
}
.w-3px {
width: 3px;
}
.w-4px {
width: 4px;
}
.w-5px {
width: 5px;
}
.w-6px {
width: 6px;
}
.w-7px {
width: 7px;
}
.w-8px {
width: 8px;
}
.w-9px {
width: 9px;
}
.w-10px {
width: 10px;
}
.h-0px {
height: 0;
}
.h-1px {
height: 1px;
}
.h-2px {
height: 2px;
}
.h-3px {
height: 3px;
}
.h-4px {
height: 4px;
}
.h-5px {
height: 5px;
}
.h-6px {
height: 6px;
}
.h-7px {
height: 7px;
}
.h-8px {
height: 8px;
}
.h-9px {
height: 9px;
}
.h-10px {
height: 10px;
}
`)
})
})