1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 15:49:44 -05:00

refactor(cli): Add TestFailureDescription (#22267)

Extract zero-risk changes from #22226
This commit is contained in:
Matt Mastracci 2024-02-05 10:27:17 -07:00 committed by GitHub
parent cb407bb546
commit aecad7f353
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 38 additions and 13 deletions

View file

@ -363,7 +363,9 @@ impl TestRun {
test::TestResult::Ignored => summary.ignored += 1,
test::TestResult::Failed(error) => {
summary.failed += 1;
summary.failures.push((description.clone(), error.clone()));
summary
.failures
.push(((&description).into(), error.clone()));
}
test::TestResult::Cancelled => {
summary.failed += 1;

View file

@ -177,6 +177,27 @@ pub struct TestDescription {
pub location: TestLocation,
}
/// May represent a failure of a test or test step.
#[derive(Debug, Clone, PartialEq, Deserialize, Eq, Hash)]
#[serde(rename_all = "camelCase")]
pub struct TestFailureDescription {
pub id: usize,
pub name: String,
pub origin: String,
pub location: TestLocation,
}
impl From<&TestDescription> for TestFailureDescription {
fn from(value: &TestDescription) -> Self {
Self {
id: value.id,
name: value.name.clone(),
origin: value.origin.clone(),
location: value.location.clone(),
}
}
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Debug, Clone, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
@ -332,7 +353,7 @@ pub struct TestSummary {
pub ignored_steps: usize,
pub filtered_out: usize,
pub measured: usize,
pub failures: Vec<(TestDescription, TestFailure)>,
pub failures: Vec<(TestFailureDescription, TestFailure)>,
pub uncaught_errors: Vec<(String, Box<JsError>)>,
}

View file

@ -33,7 +33,10 @@ pub(super) fn format_test_step_ancestry(
result
}
pub fn format_test_for_summary(cwd: &Url, desc: &TestDescription) -> String {
pub fn format_test_for_summary(
cwd: &Url,
desc: &TestFailureDescription,
) -> String {
format!(
"{} {}",
&desc.name,
@ -78,7 +81,7 @@ pub(super) fn report_sigint(
let mut formatted_pending = BTreeSet::new();
for id in tests_pending {
if let Some(desc) = tests.get(id) {
formatted_pending.insert(format_test_for_summary(cwd, desc));
formatted_pending.insert(format_test_for_summary(cwd, &desc.into()));
}
if let Some(desc) = test_steps.get(id) {
formatted_pending
@ -107,7 +110,10 @@ pub(super) fn report_summary(
#[allow(clippy::type_complexity)] // Type alias doesn't look better here
let mut failures_by_origin: BTreeMap<
String,
(Vec<(&TestDescription, &TestFailure)>, Option<&JsError>),
(
Vec<(&TestFailureDescription, &TestFailure)>,
Option<&JsError>,
),
> = BTreeMap::default();
let mut failure_titles = vec![];
for (description, failure) in &summary.failures {

View file

@ -113,7 +113,7 @@ impl TestReporter for DotTestReporter {
self
.summary
.failures
.push((description.clone(), failure.clone()));
.push((description.into(), failure.clone()));
}
TestResult::Cancelled => {
self.summary.failed += 1;
@ -162,11 +162,9 @@ impl TestReporter for DotTestReporter {
TestStepResult::Failed(failure) => {
self.summary.failed_steps += 1;
self.summary.failures.push((
TestDescription {
TestFailureDescription {
id: desc.id,
name: common::format_test_step_ancestry(desc, tests, test_steps),
ignore: false,
only: false,
origin: desc.origin.clone(),
location: desc.location.clone(),
},

View file

@ -233,7 +233,7 @@ impl TestReporter for PrettyTestReporter {
self
.summary
.failures
.push((description.clone(), failure.clone()));
.push((description.into(), failure.clone()));
}
TestResult::Cancelled => {
self.summary.failed += 1;
@ -318,11 +318,9 @@ impl TestReporter for PrettyTestReporter {
TestStepResult::Failed(failure) => {
self.summary.failed_steps += 1;
self.summary.failures.push((
TestDescription {
TestFailureDescription {
id: desc.id,
name: common::format_test_step_ancestry(desc, tests, test_steps),
ignore: false,
only: false,
origin: desc.origin.clone(),
location: desc.location.clone(),
},