|
| 1 | +use crate::run_cli; |
| 2 | +use crate::snap_test::{SnapshotPayload, assert_cli_snapshot}; |
| 3 | +use biome_console::BufferConsole; |
| 4 | +use biome_fs::{FileSystem, MemoryFileSystem}; |
| 5 | +use bpaf::Args; |
| 6 | +use camino::Utf8Path; |
| 7 | + |
| 8 | +#[test] |
| 9 | +fn can_read_hidden_biome_json_file() { |
| 10 | + let fs = MemoryFileSystem::default(); |
| 11 | + let mut console = BufferConsole::default(); |
| 12 | + |
| 13 | + let file_path = Utf8Path::new("src/index.js"); |
| 14 | + fs.insert(file_path.into(), "a['b'] = 42;".as_bytes()); |
| 15 | + |
| 16 | + let config_path = Utf8Path::new(".biome.json"); |
| 17 | + fs.insert( |
| 18 | + config_path.into(), |
| 19 | + r#"{ |
| 20 | + "javascript": { |
| 21 | + "formatter": { |
| 22 | + "quoteStyle": "single" |
| 23 | + } |
| 24 | + } |
| 25 | +}"# |
| 26 | + .as_bytes(), |
| 27 | + ); |
| 28 | + |
| 29 | + let (fs, result) = run_cli(fs, &mut console, Args::from(["check"].as_slice())); |
| 30 | + |
| 31 | + assert!(result.is_err(), "run_cli returned {result:?}"); |
| 32 | + |
| 33 | + assert_cli_snapshot(SnapshotPayload::new( |
| 34 | + module_path!(), |
| 35 | + "can_read_hidden_biome_json_file", |
| 36 | + fs, |
| 37 | + console, |
| 38 | + result, |
| 39 | + )); |
| 40 | +} |
| 41 | + |
| 42 | +#[test] |
| 43 | +fn can_read_hidden_biome_jsonc_file() { |
| 44 | + let fs = MemoryFileSystem::default(); |
| 45 | + let mut console = BufferConsole::default(); |
| 46 | + |
| 47 | + let file_path = Utf8Path::new("src/index.js"); |
| 48 | + fs.insert(file_path.into(), "a['b'] = 42;".as_bytes()); |
| 49 | + |
| 50 | + let config_path = Utf8Path::new(".biome.jsonc"); |
| 51 | + fs.insert( |
| 52 | + config_path.into(), |
| 53 | + r#"{ |
| 54 | + "javascript": { |
| 55 | + "formatter": { |
| 56 | + // comment |
| 57 | + "quoteStyle": "single" |
| 58 | + } |
| 59 | + } |
| 60 | +}"# |
| 61 | + .as_bytes(), |
| 62 | + ); |
| 63 | + |
| 64 | + let (fs, result) = run_cli(fs, &mut console, Args::from(["check"].as_slice())); |
| 65 | + |
| 66 | + assert!(result.is_err(), "run_cli returned {result:?}"); |
| 67 | + |
| 68 | + assert_cli_snapshot(SnapshotPayload::new( |
| 69 | + module_path!(), |
| 70 | + "can_read_hidden_biome_jsonc_file", |
| 71 | + fs, |
| 72 | + console, |
| 73 | + result, |
| 74 | + )); |
| 75 | +} |
| 76 | + |
| 77 | +#[test] |
| 78 | +fn can_read_configuration_from_user_home() { |
| 79 | + let fs = MemoryFileSystem::default(); |
| 80 | + let mut console = BufferConsole::default(); |
| 81 | + |
| 82 | + let file_path = Utf8Path::new("src/index.js"); |
| 83 | + fs.insert(file_path.into(), "a['b'] = 42;".as_bytes()); |
| 84 | + |
| 85 | + let config_dir = fs.user_config_dir().expect("config dir to exist"); |
| 86 | + let config_file = config_dir.join("biome.json"); |
| 87 | + fs.insert( |
| 88 | + config_file, |
| 89 | + r#"{ |
| 90 | + "javascript": { |
| 91 | + "formatter": { |
| 92 | + "quoteStyle": "single" |
| 93 | + } |
| 94 | + } |
| 95 | +}"# |
| 96 | + .as_bytes(), |
| 97 | + ); |
| 98 | + |
| 99 | + let (fs, result) = run_cli(fs, &mut console, Args::from(["check"].as_slice())); |
| 100 | + |
| 101 | + assert!(result.is_err(), "run_cli returned {result:?}"); |
| 102 | + |
| 103 | + assert_cli_snapshot(SnapshotPayload::new( |
| 104 | + module_path!(), |
| 105 | + "can_read_configuration_from_user_home", |
| 106 | + fs, |
| 107 | + console, |
| 108 | + result, |
| 109 | + )); |
| 110 | +} |
| 111 | + |
| 112 | +#[test] |
| 113 | +fn uses_project_config_before_user_config() { |
| 114 | + let fs = MemoryFileSystem::default(); |
| 115 | + let mut console = BufferConsole::default(); |
| 116 | + |
| 117 | + let file_path = Utf8Path::new("src/index.js"); |
| 118 | + fs.insert(file_path.into(), "a['b'] = 42;".as_bytes()); |
| 119 | + |
| 120 | + let config_path = Utf8Path::new(".biome.json"); |
| 121 | + fs.insert( |
| 122 | + config_path.into(), |
| 123 | + r#"{ |
| 124 | + "javascript": { |
| 125 | + "formatter": { |
| 126 | + "quoteStyle": "single" |
| 127 | + } |
| 128 | + } |
| 129 | +}"# |
| 130 | + .as_bytes(), |
| 131 | + ); |
| 132 | + |
| 133 | + let config_dir = fs.user_config_dir().expect("config dir to exist"); |
| 134 | + let config_file = config_dir.join("biome.json"); |
| 135 | + fs.insert( |
| 136 | + config_file, |
| 137 | + r#"{ |
| 138 | + "javascript": { |
| 139 | + "formatter": { |
| 140 | + "enabled": false |
| 141 | + } |
| 142 | + } |
| 143 | +}"# |
| 144 | + .as_bytes(), |
| 145 | + ); |
| 146 | + |
| 147 | + let (fs, result) = run_cli(fs, &mut console, Args::from(["check"].as_slice())); |
| 148 | + |
| 149 | + assert!(result.is_err(), "run_cli returned {result:?}"); |
| 150 | + |
| 151 | + assert_cli_snapshot(SnapshotPayload::new( |
| 152 | + module_path!(), |
| 153 | + "uses_project_config_before_user_config", |
| 154 | + fs, |
| 155 | + console, |
| 156 | + result, |
| 157 | + )); |
| 158 | +} |
0 commit comments