Skip to content

Commit

Permalink
fix(tasks): find the right output to diff (#1596)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysteryven authored Dec 3, 2023
1 parent b7b3073 commit 2f90ca1
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions tasks/prettier_conformance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,25 @@ impl TestRunner {
output = Self::visualize_end_of_line(&output);
}

let space_line = " ".repeat(prettier_options.print_width);
let snapshot_without_output = format!(
r#"
{title}
====================================options=====================================
{snapshot_options}
{space_line}| printWidth
=====================================input======================================
{input}"#
);

let snapshot_output = format!(
r#"
=====================================output=====================================
{output}
================================================================================
`;"#
);

if self.options.filter.is_some() {
println!("Input path: {}", path.to_string_lossy());
if !snapshot_line.is_empty() {
Expand All @@ -303,26 +322,13 @@ impl TestRunner {
println!("{input}");
println!("Output:");
println!("{output}");
let expected = Self::get_expect(snap_content, input.as_str()).unwrap_or_default();
let expected =
Self::get_expect(snap_content, &snapshot_without_output).unwrap_or_default();
println!("Diff:");
println!("{}", Self::get_diff(&output, &expected));
}

let space_line = " ".repeat(prettier_options.print_width);

format!(
r#"
{title}
====================================options=====================================
{snapshot_options}
{space_line}| printWidth
=====================================input======================================
{input}
=====================================output=====================================
{output}
================================================================================
`;"#
)
format!("{snapshot_without_output}{snapshot_output}")
}

fn get_expect(expected: &str, input: &str) -> Option<String> {
Expand Down

0 comments on commit 2f90ca1

Please sign in to comment.