From f80506db4ab6af3b22c29a606e6f97782d1aee63 Mon Sep 17 00:00:00 2001 From: l3ops Date: Mon, 14 Nov 2022 14:10:43 +0100 Subject: [PATCH] refactor(rome_cli): improve the stability of the `max_diagnostics` tests --- crates/rome_cli/tests/commands/check.rs | 68 +++++++++++++++++- crates/rome_cli/tests/commands/ci.rs | 70 ++++++++++++++++++- crates/rome_cli/tests/commands/format.rs | 70 ++++++++++++++++++- .../main_commands_check/max_diagnostics.snap | 13 ++++ .../max_diagnostics_default.snap | 13 ++++ .../main_commands_ci/max_diagnostics.snap | 13 ++++ .../max_diagnostics_default.snap | 13 ++++ .../main_commands_format/max_diagnostics.snap | 13 ++++ .../max_diagnostics_default.snap | 13 ++++ 9 files changed, 277 insertions(+), 9 deletions(-) create mode 100644 crates/rome_cli/tests/snapshots/main_commands_check/max_diagnostics.snap create mode 100644 crates/rome_cli/tests/snapshots/main_commands_check/max_diagnostics_default.snap create mode 100644 crates/rome_cli/tests/snapshots/main_commands_ci/max_diagnostics.snap create mode 100644 crates/rome_cli/tests/snapshots/main_commands_ci/max_diagnostics_default.snap create mode 100644 crates/rome_cli/tests/snapshots/main_commands_format/max_diagnostics.snap create mode 100644 crates/rome_cli/tests/snapshots/main_commands_format/max_diagnostics_default.snap diff --git a/crates/rome_cli/tests/commands/check.rs b/crates/rome_cli/tests/commands/check.rs index d5f9d47ae5c..d67553a1820 100644 --- a/crates/rome_cli/tests/commands/check.rs +++ b/crates/rome_cli/tests/commands/check.rs @@ -17,7 +17,7 @@ use crate::configs::{ }; use crate::snap_test::SnapshotPayload; use crate::{assert_cli_snapshot, run_cli, FORMATTED, LINT_ERROR, PARSE_ERROR}; -use rome_console::{BufferConsole, LogLevel}; +use rome_console::{BufferConsole, LogLevel, MarkupBuf}; use rome_fs::{ErrorEntry, FileSystemExt, MemoryFileSystem, OsFileSystem}; use rome_service::DynRef; @@ -939,7 +939,38 @@ fn max_diagnostics_default() { _ => panic!("run_cli returned {result:?} for a failed CI check, expected an error"), } - assert_eq!(console.out_buffer.len(), 21); + let mut diagnostic_count = 0; + let mut filtered_messages = Vec::new(); + + for msg in console.out_buffer { + let MarkupBuf(nodes) = &msg.content; + let is_diagnostic = nodes.iter().any(|node| { + node.content.contains("useWhile") || node.content.contains("useBlockStatements") + }); + + if is_diagnostic { + diagnostic_count += 1; + } else { + filtered_messages.push(msg); + } + } + + console.out_buffer = filtered_messages; + + for i in 0..60 { + let file_path = format!("src/file_{i}.js"); + fs.remove(Path::new(&file_path)); + } + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "max_diagnostics_default", + fs, + console, + result, + )); + + assert_eq!(diagnostic_count, 20); } #[test] @@ -968,7 +999,38 @@ fn max_diagnostics() { _ => panic!("run_cli returned {result:?} for a failed CI check, expected an error"), } - assert_eq!(console.out_buffer.len(), 11); + let mut diagnostic_count = 0; + let mut filtered_messages = Vec::new(); + + for msg in console.out_buffer { + let MarkupBuf(nodes) = &msg.content; + let is_diagnostic = nodes.iter().any(|node| { + node.content.contains("useWhile") || node.content.contains("useBlockStatements") + }); + + if is_diagnostic { + diagnostic_count += 1; + } else { + filtered_messages.push(msg); + } + } + + console.out_buffer = filtered_messages; + + for i in 0..60 { + let file_path = format!("src/file_{i}.js"); + fs.remove(Path::new(&file_path)); + } + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "max_diagnostics", + fs, + console, + result, + )); + + assert_eq!(diagnostic_count, 10); } #[test] diff --git a/crates/rome_cli/tests/commands/ci.rs b/crates/rome_cli/tests/commands/ci.rs index 8f5764435c8..7a4e0fcd476 100644 --- a/crates/rome_cli/tests/commands/ci.rs +++ b/crates/rome_cli/tests/commands/ci.rs @@ -6,7 +6,7 @@ use crate::{ }; use pico_args::Arguments; use rome_cli::Termination; -use rome_console::BufferConsole; +use rome_console::{BufferConsole, MarkupBuf}; use rome_fs::{FileSystemExt, MemoryFileSystem}; use rome_service::DynRef; use std::ffi::OsString; @@ -538,7 +538,39 @@ fn max_diagnostics_default() { _ => panic!("run_cli returned {result:?} for a failed CI check, expected an error"), } - assert_eq!(console.out_buffer.len(), 51); + let mut diagnostic_count = 0; + let mut filtered_messages = Vec::new(); + + for msg in console.out_buffer { + let MarkupBuf(nodes) = &msg.content; + let is_diagnostic = nodes.iter().any(|node| { + node.content + .contains("File content differs from formatting output") + }); + + if is_diagnostic { + diagnostic_count += 1; + } else { + filtered_messages.push(msg); + } + } + + console.out_buffer = filtered_messages; + + for i in 0..60 { + let file_path = format!("src/file_{i}.js"); + fs.remove(Path::new(&file_path)); + } + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "max_diagnostics_default", + fs, + console, + result, + )); + + assert_eq!(diagnostic_count, 50); } #[test] @@ -567,5 +599,37 @@ fn max_diagnostics() { _ => panic!("run_cli returned {result:?} for a failed CI check, expected an error"), } - assert_eq!(console.out_buffer.len(), 11); + let mut diagnostic_count = 0; + let mut filtered_messages = Vec::new(); + + for msg in console.out_buffer { + let MarkupBuf(nodes) = &msg.content; + let is_diagnostic = nodes.iter().any(|node| { + node.content + .contains("File content differs from formatting output") + }); + + if is_diagnostic { + diagnostic_count += 1; + } else { + filtered_messages.push(msg); + } + } + + console.out_buffer = filtered_messages; + + for i in 0..60 { + let file_path = format!("src/file_{i}.js"); + fs.remove(Path::new(&file_path)); + } + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "max_diagnostics", + fs, + console, + result, + )); + + assert_eq!(diagnostic_count, 10); } diff --git a/crates/rome_cli/tests/commands/format.rs b/crates/rome_cli/tests/commands/format.rs index f3f17086721..ec88da15417 100644 --- a/crates/rome_cli/tests/commands/format.rs +++ b/crates/rome_cli/tests/commands/format.rs @@ -9,7 +9,7 @@ use crate::{ }; use pico_args::Arguments; use rome_cli::Termination; -use rome_console::{markup, BufferConsole}; +use rome_console::{markup, BufferConsole, MarkupBuf}; use rome_fs::{FileSystemExt, MemoryFileSystem}; use rome_service::DynRef; use std::ffi::OsString; @@ -1300,7 +1300,39 @@ fn max_diagnostics_default() { assert!(result.is_ok(), "run_cli returned {result:?}"); - assert_eq!(console.out_buffer.len(), 52); + let mut diagnostic_count = 0; + let mut filtered_messages = Vec::new(); + + for msg in console.out_buffer { + let MarkupBuf(nodes) = &msg.content; + let is_diagnostic = nodes.iter().any(|node| { + node.content + .contains("Formatter would have printed the following content") + }); + + if is_diagnostic { + diagnostic_count += 1; + } else { + filtered_messages.push(msg); + } + } + + console.out_buffer = filtered_messages; + + for i in 0..60 { + let file_path = format!("src/file_{i}.js"); + fs.remove(Path::new(&file_path)); + } + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "max_diagnostics_default", + fs, + console, + result, + )); + + assert_eq!(diagnostic_count, 50); } #[test] @@ -1326,7 +1358,39 @@ fn max_diagnostics() { assert!(result.is_ok(), "run_cli returned {result:?}"); - assert_eq!(console.out_buffer.len(), 12); + let mut diagnostic_count = 0; + let mut filtered_messages = Vec::new(); + + for msg in console.out_buffer { + let MarkupBuf(nodes) = &msg.content; + let is_diagnostic = nodes.iter().any(|node| { + node.content + .contains("Formatter would have printed the following content") + }); + + if is_diagnostic { + diagnostic_count += 1; + } else { + filtered_messages.push(msg); + } + } + + console.out_buffer = filtered_messages; + + for i in 0..60 { + let file_path = format!("src/file_{i}.js"); + fs.remove(Path::new(&file_path)); + } + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "max_diagnostics", + fs, + console, + result, + )); + + assert_eq!(diagnostic_count, 10); } #[test] diff --git a/crates/rome_cli/tests/snapshots/main_commands_check/max_diagnostics.snap b/crates/rome_cli/tests/snapshots/main_commands_check/max_diagnostics.snap new file mode 100644 index 00000000000..a281bbc5464 --- /dev/null +++ b/crates/rome_cli/tests/snapshots/main_commands_check/max_diagnostics.snap @@ -0,0 +1,13 @@ +--- +source: crates/rome_cli/tests/snap_test.rs +expression: content +--- +# Termination Message + +```block +some errors were emitted while running checks +``` + +# Emitted Messages + + diff --git a/crates/rome_cli/tests/snapshots/main_commands_check/max_diagnostics_default.snap b/crates/rome_cli/tests/snapshots/main_commands_check/max_diagnostics_default.snap new file mode 100644 index 00000000000..a281bbc5464 --- /dev/null +++ b/crates/rome_cli/tests/snapshots/main_commands_check/max_diagnostics_default.snap @@ -0,0 +1,13 @@ +--- +source: crates/rome_cli/tests/snap_test.rs +expression: content +--- +# Termination Message + +```block +some errors were emitted while running checks +``` + +# Emitted Messages + + diff --git a/crates/rome_cli/tests/snapshots/main_commands_ci/max_diagnostics.snap b/crates/rome_cli/tests/snapshots/main_commands_ci/max_diagnostics.snap new file mode 100644 index 00000000000..a281bbc5464 --- /dev/null +++ b/crates/rome_cli/tests/snapshots/main_commands_ci/max_diagnostics.snap @@ -0,0 +1,13 @@ +--- +source: crates/rome_cli/tests/snap_test.rs +expression: content +--- +# Termination Message + +```block +some errors were emitted while running checks +``` + +# Emitted Messages + + diff --git a/crates/rome_cli/tests/snapshots/main_commands_ci/max_diagnostics_default.snap b/crates/rome_cli/tests/snapshots/main_commands_ci/max_diagnostics_default.snap new file mode 100644 index 00000000000..a281bbc5464 --- /dev/null +++ b/crates/rome_cli/tests/snapshots/main_commands_ci/max_diagnostics_default.snap @@ -0,0 +1,13 @@ +--- +source: crates/rome_cli/tests/snap_test.rs +expression: content +--- +# Termination Message + +```block +some errors were emitted while running checks +``` + +# Emitted Messages + + diff --git a/crates/rome_cli/tests/snapshots/main_commands_format/max_diagnostics.snap b/crates/rome_cli/tests/snapshots/main_commands_format/max_diagnostics.snap new file mode 100644 index 00000000000..1d430b5e506 --- /dev/null +++ b/crates/rome_cli/tests/snapshots/main_commands_format/max_diagnostics.snap @@ -0,0 +1,13 @@ +--- +source: crates/rome_cli/tests/snap_test.rs +assertion_line: 223 +expression: content +--- +# Emitted Messages + +```block +The number of diagnostics exceeds the number allowed by Rome. +Diagnostics not shown: 50. +``` + + diff --git a/crates/rome_cli/tests/snapshots/main_commands_format/max_diagnostics_default.snap b/crates/rome_cli/tests/snapshots/main_commands_format/max_diagnostics_default.snap new file mode 100644 index 00000000000..a55417c211a --- /dev/null +++ b/crates/rome_cli/tests/snapshots/main_commands_format/max_diagnostics_default.snap @@ -0,0 +1,13 @@ +--- +source: crates/rome_cli/tests/snap_test.rs +assertion_line: 223 +expression: content +--- +# Emitted Messages + +```block +The number of diagnostics exceeds the number allowed by Rome. +Diagnostics not shown: 10. +``` + +