Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(tasks): print diff for minify idempotency assertion #8161

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading