diff --git a/apps/oxfmt/tests/mod.rs b/apps/oxfmt/tests/mod.rs index 4ddddbae7e2e8..1f50f70cbe466 100644 --- a/apps/oxfmt/tests/mod.rs +++ b/apps/oxfmt/tests/mod.rs @@ -8,6 +8,7 @@ use tester::Tester; fn single_file() { // Test different flags on the same file Tester::new().with_cwd(PathBuf::from("tests/fixtures/single_file")).test_and_snapshot_multiple( + "single_file", &[&["--check", "simple.js"], &["--list-different", "simple.js"]], ); } @@ -17,31 +18,37 @@ fn multiple_files() { // Test different ways to specify multiple files Tester::new() .with_cwd(PathBuf::from("tests/fixtures/multiple_files")) - .test_and_snapshot_multiple(&[ - // Explicit file list - &["--check", "simple.js", "arrow.js"], - // Default to current directory - &["--check"], - // Explicit cwd - &["--check", "."], - &["--check", "./"], - ]); + .test_and_snapshot_multiple( + "multiple_files", + &[ + // Explicit file list + &["--check", "simple.js", "arrow.js"], + // Default to current directory + &["--check"], + // Explicit cwd + &["--check", "."], + &["--check", "./"], + ], + ); } #[test] fn no_error_on_unmatched_pattern() { // Test both with and without --no-error-on-unmatched-pattern flag - Tester::new().test_and_snapshot_multiple(&[ - &["--check", "--no-error-on-unmatched-pattern", "__non__existent__file.js"], - &["--check", "__non__existent__file.js"], - ]); + Tester::new().test_and_snapshot_multiple( + "no_error_on_unmatched_pattern", + &[ + &["--check", "--no-error-on-unmatched-pattern", "__non__existent__file.js"], + &["--check", "__non__existent__file.js"], + ], + ); } #[test] fn supported_extensions() { Tester::new() .with_cwd(PathBuf::from("tests/fixtures/extensions")) - .test_and_snapshot_multiple(&[&["--check"]]); + .test_and_snapshot_multiple("supported_extensions", &[&["--check"]]); } #[test] @@ -55,20 +62,21 @@ fn write_mode() { fn config_file_auto_discovery() { Tester::new() .with_cwd(PathBuf::from("tests/fixtures/config_file")) - .test_and_snapshot_multiple(&[&["--check"]]); + .test_and_snapshot_multiple("config_file_auto_discovery", &[&["--check"]]); Tester::new() .with_cwd(PathBuf::from("tests/fixtures/config_file/nested")) - .test_and_snapshot_multiple(&[&["--check"]]); + .test_and_snapshot_multiple("config_file_auto_discovery_nested", &[&["--check"]]); Tester::new() .with_cwd(PathBuf::from("tests/fixtures/config_file/nested/deep")) - .test_and_snapshot_multiple(&[&["--check"]]); + .test_and_snapshot_multiple("config_file_auto_discovery_nested_deep", &[&["--check"]]); } #[test] fn config_file_explicit() { Tester::new().with_cwd(PathBuf::from("tests/fixtures/config_file")).test_and_snapshot_multiple( + "config_file_explicit", &[ &["--check", "--config", "./fmt.json"], &["--check", "--config", "./fmt.jsonc"], @@ -83,7 +91,7 @@ fn vcs_dirs_ignored() { // but regular directories and root files are processed Tester::new() .with_cwd(PathBuf::from("tests/fixtures/vcs_dirs")) - .test_and_snapshot_multiple(&[&["--check"]]); + .test_and_snapshot_multiple("vcs_dirs_ignored", &[&["--check"]]); } #[test] @@ -92,7 +100,10 @@ fn node_modules_ignored() { // but can be included with `--with-node-modules` flag Tester::new() .with_cwd(PathBuf::from("tests/fixtures/node_modules_dirs")) - .test_and_snapshot_multiple(&[&["--check"], &["--check", "--with-node-modules"]]); + .test_and_snapshot_multiple( + "node_modules_ignored", + &[&["--check"], &["--check", "--with-node-modules"]], + ); } #[test] @@ -102,38 +113,46 @@ fn exclude_nested_paths() { // All these cases should not report parse error from `foo/bar/error.js` Tester::new() .with_cwd(PathBuf::from("tests/fixtures/exclude_nested")) - .test_and_snapshot_multiple(&[ - &["--check", "!foo/bar/error.js"], - &["--check", "!foo/bar"], - &["--check", "!foo"], - &["--check", "!**/error.js"], - &["--check", "foo", "!foo/bar/error.js"], - &["--check", "foo", "!foo/bar"], - &["--check", "foo", "!**/bar/error.js"], - &["--check", "foo", "!**/bar/*"], - ]); + .test_and_snapshot_multiple( + "exclude_nested_paths", + &[ + &["--check", "!foo/bar/error.js"], + &["--check", "!foo/bar"], + &["--check", "!foo"], + &["--check", "!**/error.js"], + &["--check", "foo", "!foo/bar/error.js"], + &["--check", "foo", "!foo/bar"], + &["--check", "foo", "!**/bar/error.js"], + &["--check", "foo", "!**/bar/*"], + ], + ); } #[test] fn exclude_nested_paths_with_dot() { // All these cases should not report parse error from `foo/bar/error.js` Tester::new() .with_cwd(PathBuf::from("tests/fixtures/exclude_nested")) - .test_and_snapshot_multiple(&[ - &["--check", ".", "!foo/bar/error.js"], - &["--check", ".", "!foo/bar"], - &["--check", ".", "!foo"], - &["--check", ".", "!**/error.js"], - ]); - // Split to avoid too long file name error... + .test_and_snapshot_multiple( + "exclude_nested_paths_with_dot_1", + &[ + &["--check", ".", "!foo/bar/error.js"], + &["--check", ".", "!foo/bar"], + &["--check", ".", "!foo"], + &["--check", ".", "!**/error.js"], + ], + ); Tester::new() .with_cwd(PathBuf::from("tests/fixtures/exclude_nested")) - .test_and_snapshot_multiple(&[ - &["--check", "./foo", "!**/bar/error.js"], - &["--check", "./foo", "!**/error.js"], - &["--check", "./foo", "!**/bar/*"], - &["--check", "./foo", "!foo/bar/error.js"], - &["--check", "./foo", "!foo/bar"], - ]); + .test_and_snapshot_multiple( + "exclude_nested_paths_with_dot_2", + &[ + &["--check", "./foo", "!**/bar/error.js"], + &["--check", "./foo", "!**/error.js"], + &["--check", "./foo", "!**/bar/*"], + &["--check", "./foo", "!foo/bar/error.js"], + &["--check", "./foo", "!foo/bar"], + ], + ); } #[test] @@ -145,15 +164,18 @@ fn ignore_patterns() { // custom.ignore contains: ignored/ (only) Tester::new() .with_cwd(PathBuf::from("tests/fixtures/ignore_patterns")) - .test_and_snapshot_multiple(&[ - // Default: auto-detects only cwd/.prettierignore (ignores not-formatted/ dir) - // Note: not-formatted/.prettierignore exists but should be ignored - &["--check"], - // Explicit: uses gitignore.txt (ignores ignored/ dir, checks not-formatted/) - &["--check", "--ignore-path", "gitignore.txt"], - // Multiple files: ignores both dirs - &["--check", "--ignore-path", "gitignore.txt", "--ignore-path", ".prettierignore"], - // Nonexistent file should error - &["--check", "--ignore-path", "nonexistent.ignore"], - ]); + .test_and_snapshot_multiple( + "ignore_patterns", + &[ + // Default: auto-detects only cwd/.prettierignore (ignores not-formatted/ dir) + // Note: not-formatted/.prettierignore exists but should be ignored + &["--check"], + // Explicit: uses gitignore.txt (ignores ignored/ dir, checks not-formatted/) + &["--check", "--ignore-path", "gitignore.txt"], + // Multiple files: ignores both dirs + &["--check", "--ignore-path", "gitignore.txt", "--ignore-path", ".prettierignore"], + // Nonexistent file should error + &["--check", "--ignore-path", "nonexistent.ignore"], + ], + ); } diff --git a/apps/oxfmt/tests/snapshots/tests__fixtures__config_file_--check@oxfmt.snap b/apps/oxfmt/tests/snapshots/config_file_auto_discovery@oxfmt.snap similarity index 100% rename from apps/oxfmt/tests/snapshots/tests__fixtures__config_file_--check@oxfmt.snap rename to apps/oxfmt/tests/snapshots/config_file_auto_discovery@oxfmt.snap diff --git a/apps/oxfmt/tests/snapshots/tests__fixtures__config_file__nested_--check@oxfmt.snap b/apps/oxfmt/tests/snapshots/config_file_auto_discovery_nested@oxfmt.snap similarity index 100% rename from apps/oxfmt/tests/snapshots/tests__fixtures__config_file__nested_--check@oxfmt.snap rename to apps/oxfmt/tests/snapshots/config_file_auto_discovery_nested@oxfmt.snap diff --git a/apps/oxfmt/tests/snapshots/tests__fixtures__config_file__nested__deep_--check@oxfmt.snap b/apps/oxfmt/tests/snapshots/config_file_auto_discovery_nested_deep@oxfmt.snap similarity index 100% rename from apps/oxfmt/tests/snapshots/tests__fixtures__config_file__nested__deep_--check@oxfmt.snap rename to apps/oxfmt/tests/snapshots/config_file_auto_discovery_nested_deep@oxfmt.snap diff --git a/apps/oxfmt/tests/snapshots/tests__fixtures__config_file_--check --config .__fmt.json --check --config .__fmt.jsonc --check --config NOT_EXISTS.json@oxfmt.snap b/apps/oxfmt/tests/snapshots/config_file_explicit@oxfmt.snap similarity index 100% rename from apps/oxfmt/tests/snapshots/tests__fixtures__config_file_--check --config .__fmt.json --check --config .__fmt.jsonc --check --config NOT_EXISTS.json@oxfmt.snap rename to apps/oxfmt/tests/snapshots/config_file_explicit@oxfmt.snap diff --git a/apps/oxfmt/tests/snapshots/tests__fixtures__exclude_nested_--check !foo__bar__error.js --check !foo__bar --check !foo --check !____error.js --check foo !foo__bar__error.js --check foo !foo__bar --check foo !____bar__error.js --check foo !____bar___@oxfmt.snap b/apps/oxfmt/tests/snapshots/exclude_nested_paths@oxfmt.snap similarity index 100% rename from apps/oxfmt/tests/snapshots/tests__fixtures__exclude_nested_--check !foo__bar__error.js --check !foo__bar --check !foo --check !____error.js --check foo !foo__bar__error.js --check foo !foo__bar --check foo !____bar__error.js --check foo !____bar___@oxfmt.snap rename to apps/oxfmt/tests/snapshots/exclude_nested_paths@oxfmt.snap diff --git a/apps/oxfmt/tests/snapshots/tests__fixtures__exclude_nested_--check . !foo__bar__error.js --check . !foo__bar --check . !foo --check . !____error.js@oxfmt.snap b/apps/oxfmt/tests/snapshots/exclude_nested_paths_with_dot_1@oxfmt.snap similarity index 100% rename from apps/oxfmt/tests/snapshots/tests__fixtures__exclude_nested_--check . !foo__bar__error.js --check . !foo__bar --check . !foo --check . !____error.js@oxfmt.snap rename to apps/oxfmt/tests/snapshots/exclude_nested_paths_with_dot_1@oxfmt.snap diff --git a/apps/oxfmt/tests/snapshots/tests__fixtures__exclude_nested_--check .__foo !____bar__error.js --check .__foo !____error.js --check .__foo !____bar___ --check .__foo !foo__bar__error.js --check .__foo !foo__bar@oxfmt.snap b/apps/oxfmt/tests/snapshots/exclude_nested_paths_with_dot_2@oxfmt.snap similarity index 100% rename from apps/oxfmt/tests/snapshots/tests__fixtures__exclude_nested_--check .__foo !____bar__error.js --check .__foo !____error.js --check .__foo !____bar___ --check .__foo !foo__bar__error.js --check .__foo !foo__bar@oxfmt.snap rename to apps/oxfmt/tests/snapshots/exclude_nested_paths_with_dot_2@oxfmt.snap diff --git a/apps/oxfmt/tests/snapshots/tests__fixtures__ignore_patterns_--check --check --ignore-path gitignore.txt --check --ignore-path gitignore.txt --ignore-path .prettierignore --check --ignore-path nonexistent.ignore@oxfmt.snap b/apps/oxfmt/tests/snapshots/ignore_patterns@oxfmt.snap similarity index 100% rename from apps/oxfmt/tests/snapshots/tests__fixtures__ignore_patterns_--check --check --ignore-path gitignore.txt --check --ignore-path gitignore.txt --ignore-path .prettierignore --check --ignore-path nonexistent.ignore@oxfmt.snap rename to apps/oxfmt/tests/snapshots/ignore_patterns@oxfmt.snap diff --git a/apps/oxfmt/tests/snapshots/tests__fixtures__multiple_files_--check simple.js arrow.js --check --check . --check .__@oxfmt.snap b/apps/oxfmt/tests/snapshots/multiple_files@oxfmt.snap similarity index 100% rename from apps/oxfmt/tests/snapshots/tests__fixtures__multiple_files_--check simple.js arrow.js --check --check . --check .__@oxfmt.snap rename to apps/oxfmt/tests/snapshots/multiple_files@oxfmt.snap diff --git a/apps/oxfmt/tests/snapshots/_--check --no-error-on-unmatched-pattern __non__existent__file.js --check __non__existent__file.js@oxfmt.snap b/apps/oxfmt/tests/snapshots/no_error_on_unmatched_pattern@oxfmt.snap similarity index 100% rename from apps/oxfmt/tests/snapshots/_--check --no-error-on-unmatched-pattern __non__existent__file.js --check __non__existent__file.js@oxfmt.snap rename to apps/oxfmt/tests/snapshots/no_error_on_unmatched_pattern@oxfmt.snap diff --git a/apps/oxfmt/tests/snapshots/tests__fixtures__node_modules_dirs_--check --check --with-node-modules@oxfmt.snap b/apps/oxfmt/tests/snapshots/node_modules_ignored@oxfmt.snap similarity index 97% rename from apps/oxfmt/tests/snapshots/tests__fixtures__node_modules_dirs_--check --check --with-node-modules@oxfmt.snap rename to apps/oxfmt/tests/snapshots/node_modules_ignored@oxfmt.snap index 6a21078cddd7f..a428399cdc23b 100644 --- a/apps/oxfmt/tests/snapshots/tests__fixtures__node_modules_dirs_--check --check --with-node-modules@oxfmt.snap +++ b/apps/oxfmt/tests/snapshots/node_modules_ignored@oxfmt.snap @@ -1,6 +1,5 @@ --- source: apps/oxfmt/tests/tester.rs -assertion_line: 102 --- ########## arguments: --check diff --git a/apps/oxfmt/tests/snapshots/tests__fixtures__single_file_--check simple.js --list-different simple.js@oxfmt.snap b/apps/oxfmt/tests/snapshots/single_file@oxfmt.snap similarity index 100% rename from apps/oxfmt/tests/snapshots/tests__fixtures__single_file_--check simple.js --list-different simple.js@oxfmt.snap rename to apps/oxfmt/tests/snapshots/single_file@oxfmt.snap diff --git a/apps/oxfmt/tests/snapshots/tests__fixtures__extensions_--check@oxfmt.snap b/apps/oxfmt/tests/snapshots/supported_extensions@oxfmt.snap similarity index 100% rename from apps/oxfmt/tests/snapshots/tests__fixtures__extensions_--check@oxfmt.snap rename to apps/oxfmt/tests/snapshots/supported_extensions@oxfmt.snap diff --git a/apps/oxfmt/tests/snapshots/tests__fixtures__vcs_dirs_--check@oxfmt.snap b/apps/oxfmt/tests/snapshots/vcs_dirs_ignored@oxfmt.snap similarity index 100% rename from apps/oxfmt/tests/snapshots/tests__fixtures__vcs_dirs_--check@oxfmt.snap rename to apps/oxfmt/tests/snapshots/vcs_dirs_ignored@oxfmt.snap diff --git a/apps/oxfmt/tests/tester.rs b/apps/oxfmt/tests/tester.rs index bca3235687838..5b17f5c2ca498 100644 --- a/apps/oxfmt/tests/tester.rs +++ b/apps/oxfmt/tests/tester.rs @@ -46,7 +46,7 @@ impl Tester { /// /// # Panics /// Panics if the current working directory cannot be determined or if command parsing fails. - pub fn test_and_snapshot_multiple(&self, multiple_args: &[&[&str]]) { + pub fn test_and_snapshot_multiple(&self, snapshot_name: &str, multiple_args: &[&[&str]]) { let mut output: Vec = Vec::new(); let current_cwd = std::env::current_dir().unwrap(); let relative_dir = self.cwd.strip_prefix(¤t_cwd).unwrap_or(&self.cwd); @@ -90,16 +90,8 @@ impl Tester { let test_cwd_string = self.cwd.to_str().unwrap().cow_replace('\\', "/").to_string(); let output_string = output_string.cow_replace(&test_cwd_string, ""); - let full_args_list = - multiple_args.iter().map(|args| args.join(" ")).collect::>().join(" "); - - let snapshot_file_name = format!("{}_{}", relative_dir.to_str().unwrap(), full_args_list); - - // windows can not handle filenames with * - // allow replace instead of cow_replace. It only test - let snapshot_file_name = snapshot_file_name.cow_replace('*', "_").to_string(); settings.bind(|| { - insta::assert_snapshot!(snapshot_file_name, output_string); + insta::assert_snapshot!(snapshot_name, output_string); }); }