1- import type { DocumentClassList , State } from './state'
1+ import {
2+ getDefaultTailwindSettings ,
3+ type DocumentClassList ,
4+ type EditorState ,
5+ type State ,
6+ } from './state'
27import { test } from 'vitest'
38import { TextDocument } from 'vscode-languageserver-textdocument'
49import { findClassListsInHtmlRange } from './find'
@@ -12,26 +17,27 @@ test('test astro', async ({ expect }) => {
1217 ] . join ( '\n' )
1318
1419 let doc = TextDocument . create ( 'file://file.astro' , 'astro' , 1 , content )
20+ let defaultSettings = getDefaultTailwindSettings ( )
1521 let state : State = {
1622 blocklist : [ ] ,
23+ enabled : true ,
1724 editor : {
1825 userLanguages : { } ,
1926 getConfiguration : async ( ) => ( {
20- editor : {
21- tabSize : 1 ,
22- } ,
27+ ...defaultSettings ,
2328 tailwindCSS : {
24- classAttributes : [ 'class' ] ,
29+ ... defaultSettings . tailwindCSS ,
2530 experimental : {
31+ ...defaultSettings . tailwindCSS . experimental ,
2632 classRegex : [
2733 [ 'cva\\(([^)]*)\\)' , '["\'`]([^"\'`]*).*?["\'`]' ] ,
2834 [ 'cn\\(([^)]*)\\)' , '["\'`]([^"\'`]*).*?["\'`]' ] ,
2935 ] ,
3036 } ,
31- } as any ,
37+ } ,
3238 } ) ,
33- } as any ,
34- } as any
39+ } as EditorState ,
40+ }
3541
3642 let classLists = await findClassListsInHtmlRange ( state , doc , 'html' )
3743
@@ -81,24 +87,7 @@ test('test astro', async ({ expect }) => {
8187} )
8288
8389test ( '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 ( )
10291 const classList = `'pointer-events-auto relative flex bg-red-500',
10392 'items-center justify-between overflow-hidden',
10493 '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 }) => {
195184} )
196185
197186test ( '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 ( )
216188 const expectedResult : DocumentClassList [ ] = [
217189 {
218190 classList : 'fixed flex' ,
@@ -310,3 +282,24 @@ test('test nested classFunctions', async ({ expect }) => {
310282
311283 expect ( classLists ) . toMatchObject ( expectedResult )
312284} )
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