-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
Copy pathintegration.test.js
259 lines (228 loc) · 5.82 KB
/
integration.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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
require('isomorphic-fetch')
let $ = require('../../execute')
let { css, html, javascript } = require('../../syntax')
let { readOutputFile, appendToInputFile, writeInputFile } = require('../../io')({
output: 'dist',
input: '.',
})
let PORT = 1337
async function fetchCSS() {
let response = await fetch(`http://0.0.0.0:${PORT}/index.css`, {
headers: {
Accept: 'text/css',
},
})
return response.text()
}
describe('static build', () => {
it('should be possible to generate tailwind output', async () => {
await writeInputFile(
'index.html',
html`
<link rel="stylesheet" href="./index.css" />
<div class="font-bold"></div>
`
)
await $('vite build', {
env: { NODE_ENV: 'production' },
})
expect(await readOutputFile(/index.\w+\.css$/)).toIncludeCss(
css`
.font-bold {
font-weight: 700;
}
`
)
})
})
describe('watcher', () => {
test('classes are generated when the html file changes', async () => {
await writeInputFile(
'index.html',
html`
<link rel="stylesheet" href="./index.css" />
<div class="font-bold"></div>
`
)
let runningProcess = $(`vite --port ${PORT}`, {
env: { TAILWIND_MODE: 'watch' },
})
await runningProcess.onStdout((message) => message.includes('ready in'))
expect(await fetchCSS()).toIncludeCss(
css`
.font-bold {
font-weight: 700;
}
`
)
await appendToInputFile('index.html', html`<div class="font-normal"></div>`)
await runningProcess.onStdout((message) => message.includes('hmr update /index.css'))
expect(await fetchCSS()).toIncludeCss(
css`
.font-bold {
font-weight: 700;
}
.font-normal {
font-weight: 400;
}
`
)
await appendToInputFile('index.html', html`<div class="bg-red-500"></div>`)
await runningProcess.onStdout((message) => message.includes('hmr update /index.css'))
expect(await fetchCSS()).toIncludeCss(
css`
.bg-red-500 {
--tw-bg-opacity: 1;
background-color: rgba(239, 68, 68, var(--tw-bg-opacity));
}
.font-bold {
font-weight: 700;
}
.font-normal {
font-weight: 400;
}
`
)
return runningProcess.stop()
})
test('classes are generated when the tailwind.config.js file changes', async () => {
await writeInputFile(
'index.html',
html`
<link rel="stylesheet" href="./index.css" />
<div class="font-bold md:font-medium"></div>
`
)
let runningProcess = $(`vite --port ${PORT}`, {
env: { TAILWIND_MODE: 'watch' },
})
await runningProcess.onStdout((message) => message.includes('ready in'))
expect(await fetchCSS()).toIncludeCss(
css`
.font-bold {
font-weight: 700;
}
@media (min-width: 768px) {
.md\\:font-medium {
font-weight: 500;
}
}
`
)
await writeInputFile(
'tailwind.config.js',
javascript`
module.exports = {
content: ['./index.html'],
theme: {
extend: {
screens: {
md: '800px'
},
fontWeight: {
bold: 'bold'
}
},
},
corePlugins: {
preflight: false,
},
plugins: [],
}
`
)
await runningProcess.onStdout((message) => message.includes('hmr update /index.css'))
expect(await fetchCSS()).toIncludeCss(
css`
.font-bold {
font-weight: bold;
}
@media (min-width: 800px) {
.md\\:font-medium {
font-weight: 500;
}
}
`
)
return runningProcess.stop()
})
test('classes are generated when the index.css file changes', async () => {
await writeInputFile(
'index.html',
html`
<link rel="stylesheet" href="./index.css" />
<div class="font-bold btn"></div>
`
)
let runningProcess = $(`vite --port ${PORT}`, {
env: { TAILWIND_MODE: 'watch' },
})
await runningProcess.onStdout((message) => message.includes('ready in'))
expect(await fetchCSS()).toIncludeCss(
css`
.font-bold {
font-weight: 700;
}
`
)
await writeInputFile(
'index.css',
css`
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer components {
.btn {
@apply px-2 py-1 rounded;
}
}
`
)
await runningProcess.onStdout((message) => message.includes('hmr update /index.css'))
expect(await fetchCSS()).toIncludeCss(
css`
.btn {
border-radius: 0.25rem;
padding-left: 0.5rem;
padding-right: 0.5rem;
padding-top: 0.25rem;
padding-bottom: 0.25rem;
}
.font-bold {
font-weight: 700;
}
`
)
await writeInputFile(
'index.css',
css`
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer components {
.btn {
@apply px-2 py-1 rounded bg-red-500;
}
}
`
)
await runningProcess.onStdout((message) => message.includes('hmr update /index.css'))
expect(await fetchCSS()).toIncludeCss(
css`
.btn {
border-radius: 0.25rem;
--tw-bg-opacity: 1;
background-color: rgba(239, 68, 68, var(--tw-bg-opacity));
padding-left: 0.5rem;
padding-right: 0.5rem;
padding-top: 0.25rem;
padding-bottom: 0.25rem;
}
.font-bold {
font-weight: 700;
}
`
)
return runningProcess.stop()
})
})