1
1
#[ cfg( test) ]
2
2
mod scan_dir {
3
+ use serial_test:: serial;
3
4
use std:: fs;
4
5
use std:: process:: Command ;
5
6
6
7
use tailwindcss_oxide:: * ;
7
8
use tempfile:: tempdir;
8
9
9
- fn scan ( paths_with_content : & [ ( & str , Option < & str > ) ] ) -> ( Vec < String > , Vec < String > ) {
10
+ fn scan_with_globs (
11
+ paths_with_content : & [ ( & str , Option < & str > ) ] ,
12
+ globs : Vec < & str > ,
13
+ ) -> ( Vec < String > , Vec < String > ) {
14
+ // Ensure that every test truly runs in isolation without any cache
15
+ clear_cache ( ) ;
16
+
10
17
// Create a temporary working directory
11
18
let dir = tempdir ( ) . unwrap ( ) . into_path ( ) ;
12
19
@@ -30,7 +37,10 @@ mod scan_dir {
30
37
let base = format ! ( "{}" , dir. display( ) ) ;
31
38
32
39
// Resolve all content paths for the (temporary) current working directory
33
- let result = scan_dir ( ScanOptions { base : base. clone ( ) } ) ;
40
+ let result = scan_dir ( ScanOptions {
41
+ base : base. clone ( ) ,
42
+ content_paths : globs. iter ( ) . map ( |x| x. to_string ( ) ) . collect ( ) ,
43
+ } ) ;
34
44
35
45
let mut paths: Vec < _ > = result
36
46
. files
@@ -57,11 +67,16 @@ mod scan_dir {
57
67
( paths, result. candidates )
58
68
}
59
69
70
+ fn scan ( paths_with_content : & [ ( & str , Option < & str > ) ] ) -> ( Vec < String > , Vec < String > ) {
71
+ scan_with_globs ( paths_with_content, vec ! [ ] )
72
+ }
73
+
60
74
fn test ( paths_with_content : & [ ( & str , Option < & str > ) ] ) -> Vec < String > {
61
75
scan ( paths_with_content) . 0
62
76
}
63
77
64
78
#[ test]
79
+ #[ serial]
65
80
fn it_should_work_with_a_set_of_root_files ( ) {
66
81
let globs = test ( & [
67
82
( "index.html" , None ) ,
@@ -73,6 +88,7 @@ mod scan_dir {
73
88
}
74
89
75
90
#[ test]
91
+ #[ serial]
76
92
fn it_should_work_with_a_set_of_root_files_and_ignore_ignored_files ( ) {
77
93
let globs = test ( & [
78
94
( ".gitignore" , Some ( "b.html" ) ) ,
@@ -85,6 +101,7 @@ mod scan_dir {
85
101
}
86
102
87
103
#[ test]
104
+ #[ serial]
88
105
fn it_should_list_all_files_in_the_public_folder_explicitly ( ) {
89
106
let globs = test ( & [
90
107
( "index.html" , None ) ,
@@ -104,6 +121,7 @@ mod scan_dir {
104
121
}
105
122
106
123
#[ test]
124
+ #[ serial]
107
125
fn it_should_list_nested_folders_explicitly_in_the_public_folder ( ) {
108
126
let globs = test ( & [
109
127
( "index.html" , None ) ,
@@ -133,6 +151,7 @@ mod scan_dir {
133
151
}
134
152
135
153
#[ test]
154
+ #[ serial]
136
155
fn it_should_list_all_files_in_the_public_folder_explicitly_except_ignored_files ( ) {
137
156
let globs = test ( & [
138
157
( ".gitignore" , Some ( "public/b.html\n a.html" ) ) ,
@@ -145,6 +164,7 @@ mod scan_dir {
145
164
}
146
165
147
166
#[ test]
167
+ #[ serial]
148
168
fn it_should_use_a_glob_for_top_level_folders ( ) {
149
169
let globs = test ( & [
150
170
( "index.html" , None ) ,
@@ -162,6 +182,7 @@ mod scan_dir {
162
182
}
163
183
164
184
#[ test]
185
+ #[ serial]
165
186
fn it_should_ignore_binary_files ( ) {
166
187
let globs = test ( & [
167
188
( "index.html" , None ) ,
@@ -173,6 +194,7 @@ mod scan_dir {
173
194
}
174
195
175
196
#[ test]
197
+ #[ serial]
176
198
fn it_should_ignore_known_extensions ( ) {
177
199
let globs = test ( & [
178
200
( "index.html" , None ) ,
@@ -184,6 +206,7 @@ mod scan_dir {
184
206
}
185
207
186
208
#[ test]
209
+ #[ serial]
187
210
fn it_should_ignore_known_files ( ) {
188
211
let globs = test ( & [
189
212
( "index.html" , None ) ,
@@ -194,6 +217,7 @@ mod scan_dir {
194
217
}
195
218
196
219
#[ test]
220
+ #[ serial]
197
221
fn it_should_ignore_and_expand_nested_ignored_folders ( ) {
198
222
let globs = test ( & [
199
223
// Explicitly listed root files
@@ -280,6 +304,7 @@ mod scan_dir {
280
304
}
281
305
282
306
#[ test]
307
+ #[ serial]
283
308
fn it_should_scan_for_utilities ( ) {
284
309
let mut ignores = String :: new ( ) ;
285
310
ignores. push_str ( "# md:font-bold\n " ) ;
@@ -304,4 +329,37 @@ mod scan_dir {
304
329
vec![ "condition" , "div" , "font-bold" , "md:flex" , "px-4" ]
305
330
) ;
306
331
}
332
+
333
+ #[ test]
334
+ #[ serial]
335
+ fn it_should_scan_content_paths ( ) {
336
+ let candidates = scan_with_globs (
337
+ & [
338
+ // We know that `.styl` extensions are ignored, so they are not covered by auto content
339
+ // detection.
340
+ ( "foo.styl" , Some ( "content-['foo.styl']" ) ) ,
341
+ ] ,
342
+ vec ! [ "*.styl" ] ,
343
+ )
344
+ . 1 ;
345
+
346
+ assert_eq ! ( candidates, vec![ "content-['foo.styl']" ] ) ;
347
+ }
348
+
349
+ #[ test]
350
+ #[ serial]
351
+ fn it_should_scan_content_paths_even_when_they_are_git_ignored ( ) {
352
+ let candidates = scan_with_globs (
353
+ & [
354
+ ( ".gitignore" , Some ( "foo.styl" ) ) ,
355
+ // We know that `.styl` extensions are ignored, so they are not covered by auto content
356
+ // detection.
357
+ ( "foo.styl" , Some ( "content-['foo.styl']" ) ) ,
358
+ ] ,
359
+ vec ! [ "*.styl" ] ,
360
+ )
361
+ . 1 ;
362
+
363
+ assert_eq ! ( candidates, vec![ "content-['foo.styl']" ] ) ;
364
+ }
307
365
}
0 commit comments