@@ -5,17 +5,19 @@ import { getCss, getTestCase } from './utils'
55describe ( 'class' , ( ) => {
66 it ( 'default' , async ( ) => {
77 // const dir = path.resolve(__dirname, './fixtures/cache')
8- const twPatcher = new TailwindcssPatcher ( )
8+ const twPatcher = new TailwindcssPatcher ( {
9+ patch : {
10+ output : {
11+ removeUniversalSelector : false ,
12+ } ,
13+ } ,
14+ } )
915 expect ( twPatcher . cacheOptions . enable ) . toBe ( false )
1016 twPatcher . patch ( )
1117 await getCss ( [ getTestCase ( 'hello-world.html' ) ] )
1218 const ctxs = twPatcher . getContexts ( )
1319 expect ( ctxs . length ) . toBe ( 1 )
14- const set = await twPatcher . getClassSet ( {
15- output : {
16- removeUniversalSelector : false ,
17- } ,
18- } )
20+ const set = await twPatcher . getClassSet ( )
1921 expect ( set . size ) . toBeGreaterThan ( 0 )
2022 expect ( set . size ) . toBe ( 4 )
2123 } )
@@ -48,13 +50,17 @@ describe('class', () => {
4850 } )
4951
5052 it ( 'multiple time process sources' , async ( ) => {
51- const twPatcher = new TailwindcssPatcher ( )
53+ const twPatcher = new TailwindcssPatcher ( {
54+ patch : {
55+ output : {
56+ removeUniversalSelector : false ,
57+ } ,
58+ } ,
59+ } )
5260 await getCss ( [ 'text-[100px]' ] )
5361 let ctxs = twPatcher . getContexts ( )
5462 expect ( ctxs . length ) . toBe ( 1 )
55- let set = await twPatcher . getClassSet ( {
56- removeUniversalSelector : false ,
57- } )
63+ let set = await twPatcher . getClassSet ( )
5864 expect ( set . size ) . toBeGreaterThan ( 0 )
5965 expect ( set . size ) . toBe ( 2 )
6066 expect ( set . has ( 'text-[100px]' ) ) . toBe ( true )
@@ -64,9 +70,7 @@ describe('class', () => {
6470 await getCss ( [ 'text-[99px]' ] )
6571 ctxs = twPatcher . getContexts ( )
6672 expect ( ctxs . length ) . toBe ( 1 )
67- set = await twPatcher . getClassSet ( {
68- removeUniversalSelector : false ,
69- } )
73+ set = await twPatcher . getClassSet ( )
7074 expect ( set . size ) . toBeGreaterThan ( 0 )
7175 expect ( set . size ) . toBe ( 2 )
7276 expect ( set . has ( 'text-[99px]' ) ) . toBe ( true )
@@ -75,21 +79,49 @@ describe('class', () => {
7579 } )
7680
7781 it ( 'wxml process sources' , async ( ) => {
78- const twPatcher = new TailwindcssPatcher ( )
82+ const twPatcher = new TailwindcssPatcher ( {
83+ patch : {
84+ output : {
85+ removeUniversalSelector : false ,
86+ } ,
87+ } ,
88+ } )
7989 twPatcher . patch ( )
8090 await getCss ( [ `<view class="bg-[#7d7ac2] text-[100px] text-[#123456] {{true?'h-[30px]':'h-[45px]'}}">111</view>` ] )
8191 const ctxs = twPatcher . getContexts ( )
8292 expect ( ctxs . length ) . toBe ( 1 )
83- const set = await twPatcher . getClassSet ( {
84- removeUniversalSelector : false ,
85- } )
93+ const set = await twPatcher . getClassSet ( )
8694 expect ( set . size ) . toBeGreaterThan ( 0 )
8795 expect ( set . size ) . toBe ( 6 )
8896 expect ( set . has ( 'text-[100px]' ) ) . toBe ( true )
8997 expect ( set . has ( 'h-[30px]' ) ) . toBe ( true )
9098 expect ( set . has ( 'h-[45px]' ) ) . toBe ( true )
9199 } )
92100
101+ it ( 'wxml process sources filter' , async ( ) => {
102+ const twPatcher = new TailwindcssPatcher ( {
103+ patch : {
104+ output : {
105+ removeUniversalSelector : false ,
106+ } ,
107+ filter ( className ) {
108+ return className . includes ( 'text-[100px]' ) || className . includes ( 'h-[' )
109+ } ,
110+ } ,
111+ } )
112+ twPatcher . patch ( )
113+ await getCss ( [ `<view class="bg-[#7d7ac2] text-[100px] text-[#123456] {{true?'h-[30px]':'h-[45px]'}}">111</view>` ] )
114+ const ctxs = twPatcher . getContexts ( )
115+ expect ( ctxs . length ) . toBe ( 1 )
116+ const set = await twPatcher . getClassSet ( )
117+ expect ( set . size ) . toBeGreaterThan ( 0 )
118+ expect ( set . size ) . toBe ( 3 )
119+ expect ( set . has ( 'text-[100px]' ) ) . toBe ( true )
120+ expect ( set . has ( 'h-[30px]' ) ) . toBe ( true )
121+ expect ( set . has ( 'h-[45px]' ) ) . toBe ( true )
122+ expect ( set . has ( 'bg-[#7d7ac2]' ) ) . toBe ( false )
123+ } )
124+
93125 it ( 'extract' , async ( ) => {
94126 const twPatcher = new TailwindcssPatcher ( )
95127 const filename = await twPatcher . extract ( )
0 commit comments