Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
test(rome_js_formatter): Ignore unsupported syntax from coverage (#3064)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser authored Aug 16, 2022
1 parent 24e83be commit 1431af0
Showing 1 changed file with 78 additions and 9 deletions.
87 changes: 78 additions & 9 deletions crates/rome_js_formatter/tests/prettier_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,15 +399,44 @@ impl DiffReport {
) {
match env::var("REPORT_PRETTIER") {
Ok(value) if value == "1" => {
self.state.lock().push(DiffReportItem {
file_name,
rome_formatted_result: rome_formatted_result.to_owned(),
prettier_formatted_result: prettier_formatted_result.to_owned(),
});
if !Self::is_ignored(file_name) {
self.state.lock().push(DiffReportItem {
file_name,
rome_formatted_result: rome_formatted_result.to_owned(),
prettier_formatted_result: prettier_formatted_result.to_owned(),
});
}
}
_ => {}
}
}

fn is_ignored(file_name: &str) -> bool {
let patterns = [
"arrows-bind",
"async-do-expressions",
"async-do-expressions.js",
"decimal.js",
"do-expressions.js",
"export-default-from",
"function-bind.js",
"module-blocks",
"partial-application",
"pipeline",
"record",
"throw-expressions.js",
"v8intrinsic.js",
"v8_intrinsic",
"bind-expressions",
"destructuring-private-fields",
"/do/",
"export-extension",
"js/tuple",
];

patterns.iter().any(|pattern| file_name.contains(pattern))
}

fn print(&self) {
if let Some(report) = rome_rowan::check_live() {
panic!("\n{report}")
Expand Down Expand Up @@ -522,19 +551,59 @@ impl DiffReport {
writeln!(report, "{diff}").unwrap();
writeln!(report, "```").unwrap()
}
writeln!(report).unwrap();
writeln!(
report,
"**Prettier Similarity**: {:.2}%",
single_file_compatibility * 100_f64
)
.unwrap();
writeln!(report).unwrap();
writeln!(report).unwrap();
}
// extra two space force markdown render insert a new line
report = format!(
"**File Based Average Prettier Similarity**: {:.2}% \n**Line Based Average Prettier Similarity**: {:.2}% \nthe definition of similarity you could found here: https://github.com/rome/tools/issues/2555#issuecomment-1124787893\n",

let mut header = String::from("# Overall Metrics\n\n");

writeln!(
header,
"**Average compatibility**: {:.2}",
report_metric_data.file_based_average_prettier_similarity * 100_f64,
)
.unwrap();

header.push_str(
r#"
<details>
<summary>Definition</summary>
$$average = \frac\{\sum_{file}^\{files}compatibility_\{file}}\{files}$$
</details>
"#,
);

write!(
header,
"**Compatible lines**: {:.2}",
report_metric_data.line_based_average_prettier_similarity * 100_f64
) + &report;
)
.unwrap();

header.push_str(
r#"
<details>
<summary>Definition</summary>
$$average = \frac{\sum_{file}^{files}matching\_lines_{file}}{max(lines_{rome}, lines_{prettier})}$$
</details>
[Metric definition discussion](https://github.com/rome/tools/issues/2555#issuecomment-1124787893)
"#,
);

let report = format!("{header}\n\n{report}");

write(report_filename, report).unwrap();
}

Expand Down

0 comments on commit 1431af0

Please sign in to comment.