/
integration.test.js
251 lines (220 loc) · 5.77 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
let $ = require('../../execute')
let { css, html, javascript } = require('../../syntax')
let {
readOutputFile,
appendToInputFile,
writeInputFile,
waitForOutputFileCreation,
waitForOutputFileChange,
} = require('../../io')({ output: 'dist', input: 'src' })
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 $('parcel build ./src/index.html --no-cache', {
env: { NODE_ENV: 'production' },
})
expect(await readOutputFile(/index\.\w+\.css$/)).toIncludeCss(
css`
.font-bold {
font-weight: 700;
}
`
)
})
})
describe.skip('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 = $('parcel watch ./src/index.html --no-cache')
await waitForOutputFileCreation(/index\.\w+\.css$/)
expect(await readOutputFile(/index\.\w+\.css$/)).toIncludeCss(
css`
.font-bold {
font-weight: 700;
}
`
)
await waitForOutputFileChange(/index\.\w+\.css$/, async () => {
await appendToInputFile('index.html', html`<div class="font-normal"></div>`)
})
expect(await readOutputFile(/index\.\w+\.css$/)).toIncludeCss(
css`
.font-bold {
font-weight: 700;
}
.font-normal {
font-weight: 400;
}
`
)
await waitForOutputFileChange(/index\.\w+\.css$/, async () => {
await appendToInputFile('index.html', html`<div class="bg-red-500"></div>`)
})
expect(await readOutputFile(/index\.\w+\.css$/)).toIncludeCss(
css`
.bg-red-500 {
--tw-bg-opacity: 1;
background-color: rgb(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 = $('parcel watch ./src/index.html --no-cache')
await waitForOutputFileCreation(/index\.\w+\.css$/)
expect(await readOutputFile(/index\.\w+\.css$/)).toIncludeCss(
css`
.font-bold {
font-weight: 700;
}
@media (min-width: 768px) {
.md\:font-medium {
font-weight: 500;
}
}
`
)
await waitForOutputFileChange(/index\.\w+\.css$/, async () => {
await writeInputFile(
'../tailwind.config.js',
javascript`
module.exports = {
content: ['./src/index.html'],
theme: {
extend: {
screens: {
md: '800px'
},
fontWeight: {
bold: 'bold'
}
},
},
corePlugins: {
preflight: false,
},
plugins: [],
}
`
)
})
expect(await readOutputFile(/index\.\w+\.css$/)).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="btn font-bold"></div>
`
)
let runningProcess = $('parcel watch ./src/index.html --no-cache')
await waitForOutputFileCreation(/index\.\w+\.css$/)
expect(await readOutputFile(/index\.\w+\.css$/)).toIncludeCss(
css`
.font-bold {
font-weight: 700;
}
`
)
await waitForOutputFileChange(/index\.\w+\.css$/, async () => {
await writeInputFile(
'index.css',
css`
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer components {
.btn {
@apply rounded px-2 py-1;
}
}
`
)
})
expect(await readOutputFile(/index\.\w+\.css$/)).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 waitForOutputFileChange(/index\.\w+\.css$/, async () => {
await writeInputFile(
'index.css',
css`
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer components {
.btn {
@apply rounded bg-red-500 px-2 py-1;
}
}
`
)
})
expect(await readOutputFile(/index\.\w+\.css$/)).toIncludeCss(
css`
.btn {
border-radius: 0.25rem;
--tw-bg-opacity: 1;
background-color: rgb(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()
})
})