Skip to content

Commit

Permalink
chore(tasks): print diff for minify idempotency assertion (#8161)
Browse files Browse the repository at this point in the history
Made the assertion error output more easier to understand.

Example output:

![image](https://github.com/user-attachments/assets/445910fb-b389-4884-b4c5-70a095bc523f)

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
sapphi-red and autofix-ci[bot] authored Dec 28, 2024
1 parent f3a36e1 commit 9d62284
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
19 changes: 18 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ serde-wasm-bindgen = "0.6.5"
sha1 = "0.10.6"
simdutf8 = { version = "0.1.5", features = ["aarch64_neon"] }
similar = "2.6.0"
similar-asserts = "1.6.0"
string_wizard = "0.0.25"
tempfile = "3.14.0"
tokio = "1.42.0"
Expand Down
2 changes: 2 additions & 0 deletions tasks/minsize/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ oxc_transformer = { workspace = true }
flate2 = { workspace = true }
oxc_tasks_common = { workspace = true }

cow-utils = { workspace = true }
humansize = { workspace = true }
rustc-hash = { workspace = true }
similar-asserts = { workspace = true }
23 changes: 22 additions & 1 deletion tasks/minsize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,29 @@ use oxc_span::SourceType;
use oxc_tasks_common::{project_root, TestFile, TestFiles};
use oxc_transformer::{ReplaceGlobalDefines, ReplaceGlobalDefinesConfig};
use rustc_hash::FxHashMap;
use similar_asserts::assert_eq;

// #[test]
// #[cfg(any(coverage, coverage_nightly))]
// fn test() {
// run().unwrap();
// }

macro_rules! assert_eq_minified_code {
($left:expr, $right:expr, $($arg:tt)*) => {
if $left != $right {
let normalized_left = $crate::normalize_minified_code($left);
let normalized_right = $crate::normalize_minified_code($right);
assert_eq!(normalized_left, normalized_right, $($arg)*);
}
};
}

fn normalize_minified_code(code: &str) -> String {
use cow_utils::CowUtils;
code.cow_replace(";", ";\n").cow_replace(",", ",\n").into_owned()
}

/// # Panics
/// # Errors
pub fn run() -> Result<(), io::Error> {
Expand Down Expand Up @@ -131,7 +147,12 @@ fn minify_twice(file: &TestFile) -> String {
};
let source_text1 = minify(&file.source_text, source_type, options);
let source_text2 = minify(&source_text1, source_type, options);
assert_eq!(source_text1, source_text2, "Minification failed for {}", &file.file_name);
assert_eq_minified_code!(
&source_text1,
&source_text2,
"Minification failed for {}",
&file.file_name
);
source_text2
}

Expand Down

0 comments on commit 9d62284

Please sign in to comment.