1
- const path = require ( 'path' )
2
- const fs = require ( 'fs' )
3
- const { exec } = require ( 'child_process' )
4
- const { t, yes, no, format, pluginPath } = require ( './utils' )
5
- const { promisify } = require ( 'util' )
6
- const execAsync = promisify ( exec )
7
-
8
- async function formatFixture ( name , extension ) {
9
- let binPath = path . resolve ( __dirname , '../node_modules/.bin/prettier' )
10
- let filePath = path . resolve ( __dirname , `fixtures/${ name } /index.${ extension } ` )
11
-
12
- let cmd = `${ binPath } ${ filePath } --plugin ${ pluginPath } `
13
-
14
- return execAsync ( cmd ) . then ( ( { stdout } ) => stdout . trim ( ) )
15
- }
1
+ const { t, yes, no, format } = require ( './utils' )
16
2
17
3
let html = [
18
4
t `<div class="${ yes } "></div>` ,
@@ -173,90 +159,6 @@ let tests = {
173
159
. map ( ( test ) => test . map ( ( t ) => t . replace ( / ^ ; / , '' ) ) ) ,
174
160
}
175
161
176
- let fixtures = [
177
- {
178
- name : 'no prettier config' ,
179
- dir : 'no-prettier-config' ,
180
- output : '<div class="bg-red-500 sm:bg-tomato"></div>' ,
181
- } ,
182
- {
183
- name : 'inferred config path' ,
184
- dir : 'basic' ,
185
- output : '<div class="bg-red-500 sm:bg-tomato"></div>' ,
186
- } ,
187
- {
188
- name : 'inferred config path (.cjs)' ,
189
- dir : 'cjs' ,
190
- output : '<div class="bg-red-500 sm:bg-hotpink"></div>' ,
191
- } ,
192
- {
193
- name : 'using esm config' ,
194
- dir : 'esm' ,
195
- output : '<div class="bg-red-500 sm:bg-hotpink"></div>' ,
196
- } ,
197
- {
198
- name : 'using esm config (explicit path)' ,
199
- dir : 'esm-explicit' ,
200
- output : '<div class="bg-red-500 sm:bg-hotpink"></div>' ,
201
- } ,
202
- {
203
- name : 'using ts config' ,
204
- dir : 'ts' ,
205
- output : '<div class="bg-red-500 sm:bg-hotpink"></div>' ,
206
- } ,
207
- {
208
- name : 'using ts config (explicit path)' ,
209
- dir : 'ts-explicit' ,
210
- output : '<div class="bg-red-500 sm:bg-hotpink"></div>' ,
211
- } ,
212
- {
213
- name : 'using v3.2.7' ,
214
- dir : 'v3-2' ,
215
- output : '<div class="bg-red-500 sm:bg-tomato"></div>' ,
216
- } ,
217
- {
218
- name : 'plugins' ,
219
- dir : 'plugins' ,
220
- output : '<div class="uppercase foo sm:bar"></div>' ,
221
- } ,
222
- {
223
- name : 'customizations: js/jsx' ,
224
- dir : 'custom-jsx' ,
225
- ext : 'jsx' ,
226
- output : `const a = sortMeFn("p-2 sm:p-1");
227
- const b = sortMeFn({
228
- foo: "p-2 sm:p-1",
229
- });
230
-
231
- const c = dontSortFn("sm:p-1 p-2");
232
- const d = sortMeTemplate\`p-2 sm:p-1\`;
233
- const e = dontSortMeTemplate\`sm:p-1 p-2\`;
234
- const f = tw.foo\`p-2 sm:p-1\`;
235
- const g = tw.foo.bar\`p-2 sm:p-1\`;
236
- const h = no.foo\`sm:p-1 p-2\`;
237
- const i = no.tw\`sm:p-1 p-2\`;
238
-
239
- const A = (props) => <div className={props.sortMe} />;
240
- const B = () => <A sortMe="p-2 sm:p-1" dontSort="sm:p-1 p-2" />;` ,
241
- } ,
242
- {
243
- name : 'customizations: vue' ,
244
- dir : 'custom-vue' ,
245
- ext : 'vue' ,
246
- output : `<script setup>
247
- let a = sortMeFn("p-2 sm:p-1");
248
- let b = sortMeFn({ "p-2 sm:p-1": true });
249
- let c = dontSortFn("sm:p-1 p-2");
250
- let d = sortMeTemplate\`p-2 sm:p-1\`;
251
- let e = dontSortMeTemplate\`sm:p-1 p-2\`;
252
- </script>
253
- <template>
254
- <div class="p-2 sm:p-1" sortMe="p-2 sm:p-1" dontSortMe="sm:p-1 p-2"></div>
255
- <div :class="{ 'p-2 sm:p-1': true }"></div>
256
- </template>` ,
257
- } ,
258
- ]
259
-
260
162
describe ( 'parsers' , ( ) => {
261
163
for ( let parser in tests ) {
262
164
test ( parser , async ( ) => {
@@ -281,44 +183,4 @@ describe('other', () => {
281
183
) ,
282
184
) . toEqual ( '<div class="unknown-class group peer container p-0"></div>' )
283
185
} )
284
-
285
- test ( 'explicit config path' , async ( ) => {
286
- expect (
287
- await format ( '<div class="sm:bg-tomato bg-red-500"></div>' , {
288
- tailwindConfig : path . resolve (
289
- __dirname ,
290
- 'fixtures/basic/tailwind.config.js' ,
291
- ) ,
292
- } ) ,
293
- ) . toEqual ( '<div class="bg-red-500 sm:bg-tomato"></div>' )
294
- } )
295
- } )
296
-
297
- describe ( 'fixtures' , ( ) => {
298
- let configs = [
299
- {
300
- from : __dirname + '/../.prettierignore' ,
301
- to : __dirname + '/../.prettierignore.testing' ,
302
- } ,
303
- {
304
- from : __dirname + '/../prettier.config.js' ,
305
- to : __dirname + '/../prettier.config.js.testing' ,
306
- } ,
307
- ]
308
-
309
- // Temporarily move config files out of the way so they don't interfere with the tests
310
- beforeAll ( ( ) =>
311
- Promise . all ( configs . map ( ( { from, to } ) => fs . promises . rename ( from , to ) ) ) ,
312
- )
313
-
314
- afterAll ( ( ) =>
315
- Promise . all ( configs . map ( ( { from, to } ) => fs . promises . rename ( to , from ) ) ) ,
316
- )
317
-
318
- for ( const fixture of fixtures ) {
319
- test ( fixture . name , async ( ) => {
320
- let formatted = await formatFixture ( fixture . dir , fixture . ext ?? 'html' )
321
- expect ( formatted ) . toEqual ( fixture . output )
322
- } )
323
- }
324
186
} )
0 commit comments