|
| 1 | +use crate::run_cli; |
| 2 | +use crate::snap_test::{SnapshotPayload, assert_cli_snapshot}; |
| 3 | +use biome_console::BufferConsole; |
| 4 | +use biome_fs::MemoryFileSystem; |
| 5 | +use bpaf::Args; |
| 6 | +use camino::Utf8Path; |
| 7 | + |
| 8 | +const MAIN_1: &str = r#"import { z} from "z" |
| 9 | +import { z, b , a} from "lodash" |
| 10 | +
|
| 11 | +a ==b |
| 12 | +
|
| 13 | +debugger |
| 14 | +
|
| 15 | +let f; |
| 16 | + let f;"#; |
| 17 | + |
| 18 | +const MAIN_2: &str = r#"import { z} from "z" |
| 19 | +import { z, b , a} from "lodash" |
| 20 | +
|
| 21 | +a ==b |
| 22 | +
|
| 23 | +debugger |
| 24 | +
|
| 25 | +let f; |
| 26 | + let f;"#; |
| 27 | + |
| 28 | +#[test] |
| 29 | +fn reports_diagnostics_json_check_command() { |
| 30 | + let fs = MemoryFileSystem::default(); |
| 31 | + let mut console = BufferConsole::default(); |
| 32 | + |
| 33 | + let file_path1 = Utf8Path::new("main.ts"); |
| 34 | + fs.insert(file_path1.into(), MAIN_1.as_bytes()); |
| 35 | + |
| 36 | + let file_path2 = Utf8Path::new("index.ts"); |
| 37 | + fs.insert(file_path2.into(), MAIN_2.as_bytes()); |
| 38 | + |
| 39 | + let (fs, result) = run_cli( |
| 40 | + fs, |
| 41 | + &mut console, |
| 42 | + Args::from( |
| 43 | + [ |
| 44 | + "check", |
| 45 | + "--reporter=json-pretty", |
| 46 | + file_path1.as_str(), |
| 47 | + file_path2.as_str(), |
| 48 | + ] |
| 49 | + .as_slice(), |
| 50 | + ), |
| 51 | + ); |
| 52 | + |
| 53 | + assert!(result.is_err(), "run_cli returned {result:?}"); |
| 54 | + |
| 55 | + assert_cli_snapshot(SnapshotPayload::new( |
| 56 | + module_path!(), |
| 57 | + "reports_diagnostics_json_check_command", |
| 58 | + fs, |
| 59 | + console, |
| 60 | + result, |
| 61 | + )); |
| 62 | +} |
| 63 | + |
| 64 | +#[test] |
| 65 | +fn reports_diagnostics_json_ci_command() { |
| 66 | + let fs = MemoryFileSystem::default(); |
| 67 | + let mut console = BufferConsole::default(); |
| 68 | + |
| 69 | + let file_path1 = Utf8Path::new("main.ts"); |
| 70 | + fs.insert(file_path1.into(), MAIN_1.as_bytes()); |
| 71 | + |
| 72 | + let file_path2 = Utf8Path::new("index.ts"); |
| 73 | + fs.insert(file_path2.into(), MAIN_2.as_bytes()); |
| 74 | + |
| 75 | + let (fs, result) = run_cli( |
| 76 | + fs, |
| 77 | + &mut console, |
| 78 | + Args::from( |
| 79 | + [ |
| 80 | + "ci", |
| 81 | + "--reporter=json-pretty", |
| 82 | + file_path1.as_str(), |
| 83 | + file_path2.as_str(), |
| 84 | + ] |
| 85 | + .as_slice(), |
| 86 | + ), |
| 87 | + ); |
| 88 | + |
| 89 | + assert!(result.is_err(), "run_cli returned {result:?}"); |
| 90 | + |
| 91 | + assert_cli_snapshot(SnapshotPayload::new( |
| 92 | + module_path!(), |
| 93 | + "reports_diagnostics_json_ci_command", |
| 94 | + fs, |
| 95 | + console, |
| 96 | + result, |
| 97 | + )); |
| 98 | +} |
| 99 | + |
| 100 | +#[test] |
| 101 | +fn reports_diagnostics_json_lint_command() { |
| 102 | + let fs = MemoryFileSystem::default(); |
| 103 | + let mut console = BufferConsole::default(); |
| 104 | + |
| 105 | + let file_path1 = Utf8Path::new("main.ts"); |
| 106 | + fs.insert(file_path1.into(), MAIN_1.as_bytes()); |
| 107 | + |
| 108 | + let file_path2 = Utf8Path::new("index.ts"); |
| 109 | + fs.insert(file_path2.into(), MAIN_2.as_bytes()); |
| 110 | + |
| 111 | + let (fs, result) = run_cli( |
| 112 | + fs, |
| 113 | + &mut console, |
| 114 | + Args::from( |
| 115 | + [ |
| 116 | + "lint", |
| 117 | + "--reporter=json-pretty", |
| 118 | + file_path1.as_str(), |
| 119 | + file_path2.as_str(), |
| 120 | + ] |
| 121 | + .as_slice(), |
| 122 | + ), |
| 123 | + ); |
| 124 | + |
| 125 | + assert!(result.is_err(), "run_cli returned {result:?}"); |
| 126 | + |
| 127 | + assert_cli_snapshot(SnapshotPayload::new( |
| 128 | + module_path!(), |
| 129 | + "reports_diagnostics_json_lint_command", |
| 130 | + fs, |
| 131 | + console, |
| 132 | + result, |
| 133 | + )); |
| 134 | +} |
| 135 | + |
| 136 | +#[test] |
| 137 | +fn reports_diagnostics_json_format_command() { |
| 138 | + let fs = MemoryFileSystem::default(); |
| 139 | + let mut console = BufferConsole::default(); |
| 140 | + |
| 141 | + let file_path1 = Utf8Path::new("main.ts"); |
| 142 | + fs.insert(file_path1.into(), MAIN_1.as_bytes()); |
| 143 | + |
| 144 | + let file_path2 = Utf8Path::new("index.ts"); |
| 145 | + fs.insert(file_path2.into(), MAIN_2.as_bytes()); |
| 146 | + |
| 147 | + let (fs, result) = run_cli( |
| 148 | + fs, |
| 149 | + &mut console, |
| 150 | + Args::from( |
| 151 | + [ |
| 152 | + "format", |
| 153 | + "--reporter=json-pretty", |
| 154 | + file_path1.as_str(), |
| 155 | + file_path2.as_str(), |
| 156 | + ] |
| 157 | + .as_slice(), |
| 158 | + ), |
| 159 | + ); |
| 160 | + |
| 161 | + assert!(result.is_err(), "run_cli returned {result:?}"); |
| 162 | + |
| 163 | + assert_cli_snapshot(SnapshotPayload::new( |
| 164 | + module_path!(), |
| 165 | + "reports_diagnostics_json_format_command", |
| 166 | + fs, |
| 167 | + console, |
| 168 | + result, |
| 169 | + )); |
| 170 | +} |
| 171 | + |
| 172 | +#[test] |
| 173 | +fn reports_diagnostics_json_check_command_file() { |
| 174 | + let fs = MemoryFileSystem::default(); |
| 175 | + let mut console = BufferConsole::default(); |
| 176 | + |
| 177 | + let file_path1 = Utf8Path::new("main.ts"); |
| 178 | + fs.insert(file_path1.into(), MAIN_1.as_bytes()); |
| 179 | + |
| 180 | + let file_path2 = Utf8Path::new("index.ts"); |
| 181 | + fs.insert(file_path2.into(), MAIN_2.as_bytes()); |
| 182 | + |
| 183 | + let (fs, result) = run_cli( |
| 184 | + fs, |
| 185 | + &mut console, |
| 186 | + Args::from( |
| 187 | + [ |
| 188 | + "check", |
| 189 | + "--reporter=json-pretty", |
| 190 | + "--reporter-file=file.json", |
| 191 | + file_path1.as_str(), |
| 192 | + file_path2.as_str(), |
| 193 | + ] |
| 194 | + .as_slice(), |
| 195 | + ), |
| 196 | + ); |
| 197 | + |
| 198 | + assert!(result.is_err(), "run_cli returned {result:?}"); |
| 199 | + |
| 200 | + assert_cli_snapshot(SnapshotPayload::new( |
| 201 | + module_path!(), |
| 202 | + "reports_diagnostics_json_check_command_file", |
| 203 | + fs, |
| 204 | + console, |
| 205 | + result, |
| 206 | + )); |
| 207 | +} |
0 commit comments