1
- import type { DocumentClassList , State } from './state'
1
+ import {
2
+ getDefaultTailwindSettings ,
3
+ type DocumentClassList ,
4
+ type EditorState ,
5
+ type State ,
6
+ } from './state'
2
7
import { test } from 'vitest'
3
8
import { TextDocument } from 'vscode-languageserver-textdocument'
4
9
import { findClassListsInHtmlRange } from './find'
@@ -12,26 +17,27 @@ test('test astro', async ({ expect }) => {
12
17
] . join ( '\n' )
13
18
14
19
let doc = TextDocument . create ( 'file://file.astro' , 'astro' , 1 , content )
20
+ let defaultSettings = getDefaultTailwindSettings ( )
15
21
let state : State = {
16
22
blocklist : [ ] ,
23
+ enabled : true ,
17
24
editor : {
18
25
userLanguages : { } ,
19
26
getConfiguration : async ( ) => ( {
20
- editor : {
21
- tabSize : 1 ,
22
- } ,
27
+ ...defaultSettings ,
23
28
tailwindCSS : {
24
- classAttributes : [ 'class' ] ,
29
+ ... defaultSettings . tailwindCSS ,
25
30
experimental : {
31
+ ...defaultSettings . tailwindCSS . experimental ,
26
32
classRegex : [
27
33
[ 'cva\\(([^)]*)\\)' , '["\'`]([^"\'`]*).*?["\'`]' ] ,
28
34
[ 'cn\\(([^)]*)\\)' , '["\'`]([^"\'`]*).*?["\'`]' ] ,
29
35
] ,
30
36
} ,
31
- } as any ,
37
+ } ,
32
38
} ) ,
33
- } as any ,
34
- } as any
39
+ } as EditorState ,
40
+ }
35
41
36
42
let classLists = await findClassListsInHtmlRange ( state , doc , 'html' )
37
43
@@ -81,24 +87,7 @@ test('test astro', async ({ expect }) => {
81
87
} )
82
88
83
89
test ( 'test simple classFunctions' , async ( { expect } ) => {
84
- const state : State = {
85
- blocklist : [ ] ,
86
- editor : {
87
- userLanguages : { } ,
88
- getConfiguration : async ( ) => ( {
89
- editor : {
90
- tabSize : 1 ,
91
- } ,
92
- tailwindCSS : {
93
- classAttributes : [ 'class' ] ,
94
- experimental : {
95
- classFunctions : [ 'cva' , 'cn' ] ,
96
- } ,
97
- } ,
98
- } ) ,
99
- } ,
100
- } as any
101
-
90
+ const state = getTailwindSettingsForClassFunctions ( )
102
91
const classList = `'pointer-events-auto relative flex bg-red-500',
103
92
'items-center justify-between overflow-hidden',
104
93
'md:min-w-[20rem] md:max-w-[37.5rem] md:py-sm py-xs pl-md pr-xs gap-sm w-full',
@@ -195,24 +184,7 @@ test('test simple classFunctions', async ({ expect }) => {
195
184
} )
196
185
197
186
test ( 'test nested classFunctions' , async ( { expect } ) => {
198
- const state : State = {
199
- blocklist : [ ] ,
200
- editor : {
201
- userLanguages : { } ,
202
- getConfiguration : async ( ) => ( {
203
- editor : {
204
- tabSize : 1 ,
205
- } ,
206
- tailwindCSS : {
207
- classAttributes : [ 'class' ] ,
208
- experimental : {
209
- classFunctions : [ 'cva' , 'cn' ] ,
210
- } ,
211
- } ,
212
- } ) ,
213
- } ,
214
- } as any
215
-
187
+ const state = getTailwindSettingsForClassFunctions ( )
216
188
const expectedResult : DocumentClassList [ ] = [
217
189
{
218
190
classList : 'fixed flex' ,
@@ -310,3 +282,24 @@ test('test nested classFunctions', async ({ expect }) => {
310
282
311
283
expect ( classLists ) . toMatchObject ( expectedResult )
312
284
} )
285
+
286
+ function getTailwindSettingsForClassFunctions ( ) : State {
287
+ const defaultSettings = getDefaultTailwindSettings ( )
288
+ return {
289
+ blocklist : [ ] ,
290
+ enabled : true ,
291
+ editor : {
292
+ userLanguages : { } ,
293
+ getConfiguration : async ( ) => ( {
294
+ ...defaultSettings ,
295
+ tailwindCSS : {
296
+ ...defaultSettings . tailwindCSS ,
297
+ experimental : {
298
+ ...defaultSettings . tailwindCSS . experimental ,
299
+ classFunctions : [ 'cva' , 'cn' ] ,
300
+ } ,
301
+ } ,
302
+ } ) ,
303
+ } as EditorState ,
304
+ }
305
+ }
0 commit comments