1
+ require ( 'isomorphic-fetch' )
2
+
1
3
let $ = require ( '../../execute' )
2
4
let { css, html, javascript } = require ( '../../syntax' )
3
5
4
- let {
5
- readOutputFile,
6
- appendToInputFile,
7
- writeInputFile,
8
- waitForOutputFileCreation,
9
- waitForOutputFileChange,
10
- } = require ( '../../io' ) ( { output : 'dist' , input : '.' } )
6
+ let { readOutputFile, appendToInputFile, writeInputFile } = require ( '../../io' ) ( {
7
+ output : 'dist' ,
8
+ input : '.' ,
9
+ } )
10
+
11
+ let PORT = 1337
12
+
13
+ async function fetchCSS ( ) {
14
+ let response = await fetch ( `http://0.0.0.0:${ PORT } /index.css` , {
15
+ headers : {
16
+ Accept : 'text/css' ,
17
+ } ,
18
+ } )
19
+ return response . text ( )
20
+ }
11
21
12
22
describe ( 'static build' , ( ) => {
13
23
it ( 'should be possible to generate tailwind output' , async ( ) => {
@@ -33,7 +43,7 @@ describe('static build', () => {
33
43
} )
34
44
} )
35
45
36
- describe . skip ( 'watcher' , ( ) => {
46
+ describe ( 'watcher' , ( ) => {
37
47
test ( 'classes are generated when the html file changes' , async ( ) => {
38
48
await writeInputFile (
39
49
'index.html' ,
@@ -43,25 +53,23 @@ describe.skip('watcher', () => {
43
53
`
44
54
)
45
55
46
- let runningProcess = $ ( ' vite dev' , {
56
+ let runningProcess = $ ( ` vite --port ${ PORT } ` , {
47
57
env : { TAILWIND_MODE : 'watch' } ,
48
58
} )
59
+ await runningProcess . onStdout ( ( message ) => message . includes ( 'ready in' ) )
49
60
50
- await waitForOutputFileCreation ( / i n d e x .\w + \. c s s $ / )
51
-
52
- expect ( await readOutputFile ( / i n d e x .\w + \. c s s $ / ) ) . toIncludeCss (
61
+ expect ( await fetchCSS ( ) ) . toIncludeCss (
53
62
css `
54
63
.font-bold {
55
64
font-weight : 700 ;
56
65
}
57
66
`
58
67
)
59
68
60
- await waitForOutputFileChange ( / i n d e x .\w + \. c s s $ / , async ( ) => {
61
- await appendToInputFile ( 'index.html' , html `<div class= "font-normal" > </ div> ` )
62
- } )
69
+ await appendToInputFile ( 'index.html' , html `<div class= "font-normal" > </ div> ` )
70
+ await runningProcess . onStdout ( ( message ) => message . includes ( 'hmr update /index.css' ) )
63
71
64
- expect ( await readOutputFile ( / i n d e x . \w + \. c s s $ / ) ) . toIncludeCss (
72
+ expect ( await fetchCSS ( ) ) . toIncludeCss (
65
73
css `
66
74
.font-bold {
67
75
font-weight : 700 ;
@@ -72,11 +80,10 @@ describe.skip('watcher', () => {
72
80
`
73
81
)
74
82
75
- await waitForOutputFileChange ( / i n d e x .\w + \. c s s $ / , async ( ) => {
76
- await appendToInputFile ( 'index.html' , html `<div class= "bg-red-500" > </ div> ` )
77
- } )
83
+ await appendToInputFile ( 'index.html' , html `<div class= "bg-red-500" > </ div> ` )
84
+ await runningProcess . onStdout ( ( message ) => message . includes ( 'hmr update /index.css' ) )
78
85
79
- expect ( await readOutputFile ( / i n d e x . \w + \. c s s $ / ) ) . toIncludeCss (
86
+ expect ( await fetchCSS ( ) ) . toIncludeCss (
80
87
css `
81
88
.bg-red-500 {
82
89
--tw-bg-opacity : 1 ;
@@ -103,13 +110,12 @@ describe.skip('watcher', () => {
103
110
`
104
111
)
105
112
106
- let runningProcess = $ ( ' vite build --watch' , {
113
+ let runningProcess = $ ( ` vite --port ${ PORT } ` , {
107
114
env : { TAILWIND_MODE : 'watch' } ,
108
115
} )
116
+ await runningProcess . onStdout ( ( message ) => message . includes ( 'ready in' ) )
109
117
110
- await waitForOutputFileCreation ( 'main.css' )
111
-
112
- expect ( await readOutputFile ( 'main.css' ) ) . toIncludeCss (
118
+ expect ( await fetchCSS ( ) ) . toIncludeCss (
113
119
css `
114
120
.font-bold {
115
121
font-weight : 700 ;
@@ -122,37 +128,36 @@ describe.skip('watcher', () => {
122
128
`
123
129
)
124
130
125
- await waitForOutputFileChange ( 'main.css' , async ( ) => {
126
- await writeInputFile (
127
- 'tailwind.config.js' ,
128
- javascript `
129
- module .exports = {
130
- purge : ['./src/index.html' ],
131
- mode: 'jit' ,
132
- darkMode: false, // or 'media' or 'class'
133
- theme: {
134
- extend : {
135
- screens : {
136
- md : '800px'
137
- },
138
- fontWeight : {
139
- bold : 'bold'
140
- }
131
+ await writeInputFile (
132
+ 'tailwind.config.js' ,
133
+ javascript `
134
+ module .exports = {
135
+ purge : ['./index.html' ],
136
+ mode: 'jit' ,
137
+ darkMode: false, // or 'media' or 'class'
138
+ theme: {
139
+ extend : {
140
+ screens : {
141
+ md : '800px'
141
142
},
143
+ fontWeight : {
144
+ bold : 'bold'
145
+ }
142
146
},
143
- variants : {
144
- extend : {},
145
- },
146
- corePlugins : {
147
- preflight : false,
148
- },
149
- plugins: [ ],
150
- }
147
+ },
148
+ variants : {
149
+ extend : {},
150
+ },
151
+ corePlugins : {
152
+ preflight : false,
153
+ },
154
+ plugins: [ ],
155
+ }
151
156
`
152
- )
153
- } )
157
+ )
158
+ await runningProcess . onStdout ( ( message ) => message . includes ( 'hmr update /index.css' ) )
154
159
155
- expect ( await readOutputFile ( 'main.css' ) ) . toIncludeCss (
160
+ expect ( await fetchCSS ( ) ) . toIncludeCss (
156
161
css `
157
162
.font-bold {
158
163
font-weight : bold;
@@ -177,38 +182,36 @@ describe.skip('watcher', () => {
177
182
`
178
183
)
179
184
180
- let runningProcess = $ ( ' vite watch' , {
185
+ let runningProcess = $ ( ` vite --port ${ PORT } ` , {
181
186
env : { TAILWIND_MODE : 'watch' } ,
182
187
} )
188
+ await runningProcess . onStdout ( ( message ) => message . includes ( 'ready in' ) )
183
189
184
- await waitForOutputFileCreation ( 'main.css' )
185
-
186
- expect ( await readOutputFile ( 'main.css' ) ) . toIncludeCss (
190
+ expect ( await fetchCSS ( ) ) . toIncludeCss (
187
191
css `
188
192
.font-bold {
189
193
font-weight : 700 ;
190
194
}
191
195
`
192
196
)
193
197
194
- await waitForOutputFileChange ( 'main.css' , async ( ) => {
195
- await writeInputFile (
196
- 'index.css' ,
197
- css `
198
- @tailwind base;
199
- @tailwind components;
200
- @tailwind utilities;
198
+ await writeInputFile (
199
+ 'index.css' ,
200
+ css `
201
+ @tailwind base;
202
+ @tailwind components;
203
+ @tailwind utilities;
201
204
202
- @layer components {
203
- .btn {
204
- @apply px-2 py-1 rounded;
205
- }
205
+ @layer components {
206
+ .btn {
207
+ @apply px-2 py-1 rounded;
206
208
}
207
- `
208
- )
209
- } )
209
+ }
210
+ `
211
+ )
212
+ await runningProcess . onStdout ( ( message ) => message . includes ( 'hmr update /index.css' ) )
210
213
211
- expect ( await readOutputFile ( 'main.css' ) ) . toIncludeCss (
214
+ expect ( await fetchCSS ( ) ) . toIncludeCss (
212
215
css `
213
216
.btn {
214
217
border-radius : 0.25rem ;
@@ -223,24 +226,23 @@ describe.skip('watcher', () => {
223
226
`
224
227
)
225
228
226
- await waitForOutputFileChange ( 'main.css' , async ( ) => {
227
- await writeInputFile (
228
- 'index.css' ,
229
- css `
230
- @tailwind base;
231
- @tailwind components;
232
- @tailwind utilities;
229
+ await writeInputFile (
230
+ 'index.css' ,
231
+ css `
232
+ @tailwind base;
233
+ @tailwind components;
234
+ @tailwind utilities;
233
235
234
- @layer components {
235
- .btn {
236
- @apply px-2 py-1 rounded bg-red-500;
237
- }
236
+ @layer components {
237
+ .btn {
238
+ @apply px-2 py-1 rounded bg-red-500;
238
239
}
239
- `
240
- )
241
- } )
240
+ }
241
+ `
242
+ )
243
+ await runningProcess . onStdout ( ( message ) => message . includes ( 'hmr update /index.css' ) )
242
244
243
- expect ( await readOutputFile ( 'main.css' ) ) . toIncludeCss (
245
+ expect ( await fetchCSS ( ) ) . toIncludeCss (
244
246
css `
245
247
.btn {
246
248
border-radius : 0.25rem ;
0 commit comments