@@ -35,7 +35,7 @@ describe('search', () => {
35
35
} )
36
36
} )
37
37
38
- describe ( 'import the types from the dirs ' , ( ) => {
38
+ describe ( 'dirsScanOptions ' , ( ) => {
39
39
it ( 'should top level types enable work' , async ( ) => {
40
40
const ctx = createContext ( {
41
41
dts : false ,
@@ -88,4 +88,114 @@ describe('import the types from the dirs', () => {
88
88
expect ( data ) . not . toContain ( 'TypeB' )
89
89
expect ( data ) . toContain ( 'SpecialType' )
90
90
} )
91
+
92
+ it ( 'should filePatterns work' , async ( ) => {
93
+ const ctx = createContext ( {
94
+ dts : false ,
95
+ dirsScanOptions : {
96
+ filePatterns : [ '*.{ts,tsx}' ] ,
97
+ } ,
98
+ dirs : [
99
+ 'src/views' ,
100
+ 'src/types' ,
101
+ ] ,
102
+ } , root )
103
+
104
+ await ctx . scanDirs ( )
105
+ const data = await ctx . generateDTS ( '' )
106
+ expect ( data ) . toContain ( 'PageA' )
107
+ expect ( data ) . toContain ( 'PageB' )
108
+ expect ( data ) . toContain ( 'TypeA' )
109
+ expect ( data ) . toContain ( 'TypeB' )
110
+ expect ( data ) . toContain ( 'SpecialType' )
111
+ } )
112
+
113
+ it ( 'should specific filePatterns work' , async ( ) => {
114
+ const ctx = createContext ( {
115
+ dts : false ,
116
+ dirsScanOptions : {
117
+ types : true ,
118
+ filePatterns : [ '*.ts' ] ,
119
+ } ,
120
+ dirs : [
121
+ 'src/views' ,
122
+ 'src/types' ,
123
+ ] ,
124
+ } , root )
125
+
126
+ await ctx . scanDirs ( )
127
+ const data = await ctx . generateDTS ( '' )
128
+ expect ( data ) . not . toContain ( 'PageA' )
129
+ expect ( data ) . not . toContain ( 'PageB' )
130
+ expect ( data ) . not . toContain ( 'TypeA' )
131
+ expect ( data ) . not . toContain ( 'TypeB' )
132
+ expect ( data ) . toContain ( 'SpecialType' )
133
+ } )
134
+
135
+ it ( 'should fileFilter work' , async ( ) => {
136
+ const ctx = createContext ( {
137
+ dts : false ,
138
+ dirsScanOptions : {
139
+ types : true ,
140
+ fileFilter : ( file : string ) => file . includes ( 'TypeA' ) || file . includes ( 'PageA' ) ,
141
+ } ,
142
+ dirs : [
143
+ 'src/views' ,
144
+ 'src/types' ,
145
+ ] ,
146
+ } , root )
147
+
148
+ await ctx . scanDirs ( )
149
+ const data = await ctx . generateDTS ( '' )
150
+ expect ( data ) . toContain ( 'TypeA' )
151
+ expect ( data ) . toContain ( 'PageA' )
152
+ expect ( data ) . not . toContain ( 'TypeB' )
153
+ expect ( data ) . not . toContain ( 'PageB' )
154
+ expect ( data ) . not . toContain ( 'SpecialType' )
155
+ } )
156
+
157
+ it ( 'should fileFilter work when excluding all' , async ( ) => {
158
+ const ctx = createContext ( {
159
+ dts : false ,
160
+ dirsScanOptions : {
161
+ types : true ,
162
+ fileFilter : ( _file : string ) => false ,
163
+ } ,
164
+ dirs : [
165
+ 'src/views' ,
166
+ 'src/types' ,
167
+ ] ,
168
+ } , root )
169
+
170
+ await ctx . scanDirs ( )
171
+ const data = await ctx . generateDTS ( '' )
172
+ expect ( data ) . not . toContain ( 'TypeA' )
173
+ expect ( data ) . not . toContain ( 'PageA' )
174
+ expect ( data ) . not . toContain ( 'TypeB' )
175
+ expect ( data ) . not . toContain ( 'PageB' )
176
+ expect ( data ) . not . toContain ( 'SpecialType' )
177
+ } )
178
+
179
+ it ( 'should filePatterns and fileFilter work together' , async ( ) => {
180
+ const ctx = createContext ( {
181
+ dts : false ,
182
+ dirsScanOptions : {
183
+ types : true ,
184
+ filePatterns : [ '*.{ts,tsx}' ] ,
185
+ fileFilter : ( file : string ) => file . includes ( 'PageA' ) ,
186
+ } ,
187
+ dirs : [
188
+ 'src/views' ,
189
+ 'src/types' ,
190
+ ] ,
191
+ } , root )
192
+
193
+ await ctx . scanDirs ( )
194
+ const data = await ctx . generateDTS ( '' )
195
+ expect ( data ) . toContain ( 'PageA' )
196
+ expect ( data ) . toContain ( 'TypeA' )
197
+ expect ( data ) . not . toContain ( 'SpecialType' )
198
+ expect ( data ) . not . toContain ( 'PageB' )
199
+ expect ( data ) . not . toContain ( 'TypeB' )
200
+ } )
91
201
} )
0 commit comments