@@ -5,17 +5,19 @@ import { getCss, getTestCase } from './utils'
5
5
describe ( 'class' , ( ) => {
6
6
it ( 'default' , async ( ) => {
7
7
// 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
+ } )
9
15
expect ( twPatcher . cacheOptions . enable ) . toBe ( false )
10
16
twPatcher . patch ( )
11
17
await getCss ( [ getTestCase ( 'hello-world.html' ) ] )
12
18
const ctxs = twPatcher . getContexts ( )
13
19
expect ( ctxs . length ) . toBe ( 1 )
14
- const set = await twPatcher . getClassSet ( {
15
- output : {
16
- removeUniversalSelector : false ,
17
- } ,
18
- } )
20
+ const set = await twPatcher . getClassSet ( )
19
21
expect ( set . size ) . toBeGreaterThan ( 0 )
20
22
expect ( set . size ) . toBe ( 4 )
21
23
} )
@@ -48,13 +50,17 @@ describe('class', () => {
48
50
} )
49
51
50
52
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
+ } )
52
60
await getCss ( [ 'text-[100px]' ] )
53
61
let ctxs = twPatcher . getContexts ( )
54
62
expect ( ctxs . length ) . toBe ( 1 )
55
- let set = await twPatcher . getClassSet ( {
56
- removeUniversalSelector : false ,
57
- } )
63
+ let set = await twPatcher . getClassSet ( )
58
64
expect ( set . size ) . toBeGreaterThan ( 0 )
59
65
expect ( set . size ) . toBe ( 2 )
60
66
expect ( set . has ( 'text-[100px]' ) ) . toBe ( true )
@@ -64,9 +70,7 @@ describe('class', () => {
64
70
await getCss ( [ 'text-[99px]' ] )
65
71
ctxs = twPatcher . getContexts ( )
66
72
expect ( ctxs . length ) . toBe ( 1 )
67
- set = await twPatcher . getClassSet ( {
68
- removeUniversalSelector : false ,
69
- } )
73
+ set = await twPatcher . getClassSet ( )
70
74
expect ( set . size ) . toBeGreaterThan ( 0 )
71
75
expect ( set . size ) . toBe ( 2 )
72
76
expect ( set . has ( 'text-[99px]' ) ) . toBe ( true )
@@ -75,21 +79,49 @@ describe('class', () => {
75
79
} )
76
80
77
81
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
+ } )
79
89
twPatcher . patch ( )
80
90
await getCss ( [ `<view class="bg-[#7d7ac2] text-[100px] text-[#123456] {{true?'h-[30px]':'h-[45px]'}}">111</view>` ] )
81
91
const ctxs = twPatcher . getContexts ( )
82
92
expect ( ctxs . length ) . toBe ( 1 )
83
- const set = await twPatcher . getClassSet ( {
84
- removeUniversalSelector : false ,
85
- } )
93
+ const set = await twPatcher . getClassSet ( )
86
94
expect ( set . size ) . toBeGreaterThan ( 0 )
87
95
expect ( set . size ) . toBe ( 6 )
88
96
expect ( set . has ( 'text-[100px]' ) ) . toBe ( true )
89
97
expect ( set . has ( 'h-[30px]' ) ) . toBe ( true )
90
98
expect ( set . has ( 'h-[45px]' ) ) . toBe ( true )
91
99
} )
92
100
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
+
93
125
it ( 'extract' , async ( ) => {
94
126
const twPatcher = new TailwindcssPatcher ( )
95
127
const filename = await twPatcher . extract ( )
0 commit comments