refactor(rome_cli): improve the stability of the `max_diagnostics` tests
MODIFY
crates/rome_cli/tests/commands/check.rs
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]

MODIFY
crates/rome_cli/tests/commands/ci.rs
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);
}

MODIFY
crates/rome_cli/tests/commands/format.rs
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]

ADD
crates/rome_cli/tests/snapshots/main_commands_check/max_diagnostics.snap
+---
+source: crates/rome_cli/tests/snap_test.rs
+expression: content
+---
+# Termination Message
+
+```block
+some errors were emitted while running checks
+```
+
+# Emitted Messages
+
+

ADD
crates/rome_cli/tests/snapshots/main_commands_check/max_diagnostics_default.snap
+---
+source: crates/rome_cli/tests/snap_test.rs
+expression: content
+---
+# Termination Message
+
+```block
+some errors were emitted while running checks
+```
+
+# Emitted Messages
+
+

ADD
crates/rome_cli/tests/snapshots/main_commands_ci/max_diagnostics.snap
+---
+source: crates/rome_cli/tests/snap_test.rs
+expression: content
+---
+# Termination Message
+
+```block
+some errors were emitted while running checks
+```
+
+# Emitted Messages
+
+

ADD
crates/rome_cli/tests/snapshots/main_commands_ci/max_diagnostics_default.snap
+---
+source: crates/rome_cli/tests/snap_test.rs
+expression: content
+---
+# Termination Message
+
+```block
+some errors were emitted while running checks
+```
+
+# Emitted Messages
+
+

ADD
crates/rome_cli/tests/snapshots/main_commands_format/max_diagnostics.snap
+---
+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.
+```
+
+

ADD
crates/rome_cli/tests/snapshots/main_commands_format/max_diagnostics_default.snap
+---
+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.
+```
+
+

refactor(rome_cli): improve the stability of the `max_diagnostics` tests (#3729)