@@ -8,6 +8,7 @@ use tester::Tester;
88fn single_file ( ) {
99 // Test different flags on the same file
1010 Tester :: new ( ) . with_cwd ( PathBuf :: from ( "tests/fixtures/single_file" ) ) . test_and_snapshot_multiple (
11+ "single_file" ,
1112 & [ & [ "--check" , "simple.js" ] , & [ "--list-different" , "simple.js" ] ] ,
1213 ) ;
1314}
@@ -17,31 +18,37 @@ fn multiple_files() {
1718 // Test different ways to specify multiple files
1819 Tester :: new ( )
1920 . with_cwd ( PathBuf :: from ( "tests/fixtures/multiple_files" ) )
20- . test_and_snapshot_multiple ( & [
21- // Explicit file list
22- & [ "--check" , "simple.js" , "arrow.js" ] ,
23- // Default to current directory
24- & [ "--check" ] ,
25- // Explicit cwd
26- & [ "--check" , "." ] ,
27- & [ "--check" , "./" ] ,
28- ] ) ;
21+ . test_and_snapshot_multiple (
22+ "multiple_files" ,
23+ & [
24+ // Explicit file list
25+ & [ "--check" , "simple.js" , "arrow.js" ] ,
26+ // Default to current directory
27+ & [ "--check" ] ,
28+ // Explicit cwd
29+ & [ "--check" , "." ] ,
30+ & [ "--check" , "./" ] ,
31+ ] ,
32+ ) ;
2933}
3034
3135#[ test]
3236fn no_error_on_unmatched_pattern ( ) {
3337 // Test both with and without --no-error-on-unmatched-pattern flag
34- Tester :: new ( ) . test_and_snapshot_multiple ( & [
35- & [ "--check" , "--no-error-on-unmatched-pattern" , "__non__existent__file.js" ] ,
36- & [ "--check" , "__non__existent__file.js" ] ,
37- ] ) ;
38+ Tester :: new ( ) . test_and_snapshot_multiple (
39+ "no_error_on_unmatched_pattern" ,
40+ & [
41+ & [ "--check" , "--no-error-on-unmatched-pattern" , "__non__existent__file.js" ] ,
42+ & [ "--check" , "__non__existent__file.js" ] ,
43+ ] ,
44+ ) ;
3845}
3946
4047#[ test]
4148fn supported_extensions ( ) {
4249 Tester :: new ( )
4350 . with_cwd ( PathBuf :: from ( "tests/fixtures/extensions" ) )
44- . test_and_snapshot_multiple ( & [ & [ "--check" ] ] ) ;
51+ . test_and_snapshot_multiple ( "supported_extensions" , & [ & [ "--check" ] ] ) ;
4552}
4653
4754#[ test]
@@ -55,20 +62,21 @@ fn write_mode() {
5562fn config_file_auto_discovery ( ) {
5663 Tester :: new ( )
5764 . with_cwd ( PathBuf :: from ( "tests/fixtures/config_file" ) )
58- . test_and_snapshot_multiple ( & [ & [ "--check" ] ] ) ;
65+ . test_and_snapshot_multiple ( "config_file_auto_discovery" , & [ & [ "--check" ] ] ) ;
5966
6067 Tester :: new ( )
6168 . with_cwd ( PathBuf :: from ( "tests/fixtures/config_file/nested" ) )
62- . test_and_snapshot_multiple ( & [ & [ "--check" ] ] ) ;
69+ . test_and_snapshot_multiple ( "config_file_auto_discovery_nested" , & [ & [ "--check" ] ] ) ;
6370
6471 Tester :: new ( )
6572 . with_cwd ( PathBuf :: from ( "tests/fixtures/config_file/nested/deep" ) )
66- . test_and_snapshot_multiple ( & [ & [ "--check" ] ] ) ;
73+ . test_and_snapshot_multiple ( "config_file_auto_discovery_nested_deep" , & [ & [ "--check" ] ] ) ;
6774}
6875
6976#[ test]
7077fn config_file_explicit ( ) {
7178 Tester :: new ( ) . with_cwd ( PathBuf :: from ( "tests/fixtures/config_file" ) ) . test_and_snapshot_multiple (
79+ "config_file_explicit" ,
7280 & [
7381 & [ "--check" , "--config" , "./fmt.json" ] ,
7482 & [ "--check" , "--config" , "./fmt.jsonc" ] ,
@@ -83,7 +91,7 @@ fn vcs_dirs_ignored() {
8391 // but regular directories and root files are processed
8492 Tester :: new ( )
8593 . with_cwd ( PathBuf :: from ( "tests/fixtures/vcs_dirs" ) )
86- . test_and_snapshot_multiple ( & [ & [ "--check" ] ] ) ;
94+ . test_and_snapshot_multiple ( "vcs_dirs_ignored" , & [ & [ "--check" ] ] ) ;
8795}
8896
8997#[ test]
@@ -92,7 +100,10 @@ fn node_modules_ignored() {
92100 // but can be included with `--with-node-modules` flag
93101 Tester :: new ( )
94102 . with_cwd ( PathBuf :: from ( "tests/fixtures/node_modules_dirs" ) )
95- . test_and_snapshot_multiple ( & [ & [ "--check" ] , & [ "--check" , "--with-node-modules" ] ] ) ;
103+ . test_and_snapshot_multiple (
104+ "node_modules_ignored" ,
105+ & [ & [ "--check" ] , & [ "--check" , "--with-node-modules" ] ] ,
106+ ) ;
96107}
97108
98109#[ test]
@@ -102,38 +113,46 @@ fn exclude_nested_paths() {
102113 // All these cases should not report parse error from `foo/bar/error.js`
103114 Tester :: new ( )
104115 . with_cwd ( PathBuf :: from ( "tests/fixtures/exclude_nested" ) )
105- . test_and_snapshot_multiple ( & [
106- & [ "--check" , "!foo/bar/error.js" ] ,
107- & [ "--check" , "!foo/bar" ] ,
108- & [ "--check" , "!foo" ] ,
109- & [ "--check" , "!**/error.js" ] ,
110- & [ "--check" , "foo" , "!foo/bar/error.js" ] ,
111- & [ "--check" , "foo" , "!foo/bar" ] ,
112- & [ "--check" , "foo" , "!**/bar/error.js" ] ,
113- & [ "--check" , "foo" , "!**/bar/*" ] ,
114- ] ) ;
116+ . test_and_snapshot_multiple (
117+ "exclude_nested_paths" ,
118+ & [
119+ & [ "--check" , "!foo/bar/error.js" ] ,
120+ & [ "--check" , "!foo/bar" ] ,
121+ & [ "--check" , "!foo" ] ,
122+ & [ "--check" , "!**/error.js" ] ,
123+ & [ "--check" , "foo" , "!foo/bar/error.js" ] ,
124+ & [ "--check" , "foo" , "!foo/bar" ] ,
125+ & [ "--check" , "foo" , "!**/bar/error.js" ] ,
126+ & [ "--check" , "foo" , "!**/bar/*" ] ,
127+ ] ,
128+ ) ;
115129}
116130#[ test]
117131fn exclude_nested_paths_with_dot ( ) {
118132 // All these cases should not report parse error from `foo/bar/error.js`
119133 Tester :: new ( )
120134 . with_cwd ( PathBuf :: from ( "tests/fixtures/exclude_nested" ) )
121- . test_and_snapshot_multiple ( & [
122- & [ "--check" , "." , "!foo/bar/error.js" ] ,
123- & [ "--check" , "." , "!foo/bar" ] ,
124- & [ "--check" , "." , "!foo" ] ,
125- & [ "--check" , "." , "!**/error.js" ] ,
126- ] ) ;
127- // Split to avoid too long file name error...
135+ . test_and_snapshot_multiple (
136+ "exclude_nested_paths_with_dot_1" ,
137+ & [
138+ & [ "--check" , "." , "!foo/bar/error.js" ] ,
139+ & [ "--check" , "." , "!foo/bar" ] ,
140+ & [ "--check" , "." , "!foo" ] ,
141+ & [ "--check" , "." , "!**/error.js" ] ,
142+ ] ,
143+ ) ;
128144 Tester :: new ( )
129145 . with_cwd ( PathBuf :: from ( "tests/fixtures/exclude_nested" ) )
130- . test_and_snapshot_multiple ( & [
131- & [ "--check" , "./foo" , "!**/bar/error.js" ] ,
132- & [ "--check" , "./foo" , "!**/error.js" ] ,
133- & [ "--check" , "./foo" , "!**/bar/*" ] ,
134- & [ "--check" , "./foo" , "!foo/bar/error.js" ] ,
135- & [ "--check" , "./foo" , "!foo/bar" ] ,
136- ] ) ;
146+ . test_and_snapshot_multiple (
147+ "exclude_nested_paths_with_dot_2" ,
148+ & [
149+ & [ "--check" , "./foo" , "!**/bar/error.js" ] ,
150+ & [ "--check" , "./foo" , "!**/error.js" ] ,
151+ & [ "--check" , "./foo" , "!**/bar/*" ] ,
152+ & [ "--check" , "./foo" , "!foo/bar/error.js" ] ,
153+ & [ "--check" , "./foo" , "!foo/bar" ] ,
154+ ] ,
155+ ) ;
137156}
138157
139158#[ test]
@@ -145,15 +164,18 @@ fn ignore_patterns() {
145164 // custom.ignore contains: ignored/ (only)
146165 Tester :: new ( )
147166 . with_cwd ( PathBuf :: from ( "tests/fixtures/ignore_patterns" ) )
148- . test_and_snapshot_multiple ( & [
149- // Default: auto-detects only cwd/.prettierignore (ignores not-formatted/ dir)
150- // Note: not-formatted/.prettierignore exists but should be ignored
151- & [ "--check" ] ,
152- // Explicit: uses gitignore.txt (ignores ignored/ dir, checks not-formatted/)
153- & [ "--check" , "--ignore-path" , "gitignore.txt" ] ,
154- // Multiple files: ignores both dirs
155- & [ "--check" , "--ignore-path" , "gitignore.txt" , "--ignore-path" , ".prettierignore" ] ,
156- // Nonexistent file should error
157- & [ "--check" , "--ignore-path" , "nonexistent.ignore" ] ,
158- ] ) ;
167+ . test_and_snapshot_multiple (
168+ "ignore_patterns" ,
169+ & [
170+ // Default: auto-detects only cwd/.prettierignore (ignores not-formatted/ dir)
171+ // Note: not-formatted/.prettierignore exists but should be ignored
172+ & [ "--check" ] ,
173+ // Explicit: uses gitignore.txt (ignores ignored/ dir, checks not-formatted/)
174+ & [ "--check" , "--ignore-path" , "gitignore.txt" ] ,
175+ // Multiple files: ignores both dirs
176+ & [ "--check" , "--ignore-path" , "gitignore.txt" , "--ignore-path" , ".prettierignore" ] ,
177+ // Nonexistent file should error
178+ & [ "--check" , "--ignore-path" , "nonexistent.ignore" ] ,
179+ ] ,
180+ ) ;
159181}
0 commit comments