summaryrefslogtreecommitdiff
path: root/cli/tools
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2022-04-16 19:51:12 +0200
committerGitHub <noreply@github.com>2022-04-16 19:51:12 +0200
commit5f2d9a4a220307b1111c91dfac74951ef3925457 (patch)
tree0873546419f8f8dd9ccbaf53dd0c6aa04c78baf0 /cli/tools
parent32aaefd9eeea4a08eec0159f6374bfadf2bec62f (diff)
feat(test): use structured data for JavaScript errors in tests (#14287)
This commit rewrites test runner to send structured error data from JavaScript to Rust instead of passing strings. This will allow to customize display of errors in test report (which will be addressed in follow up commits).
Diffstat (limited to 'cli/tools')
-rw-r--r--cli/tools/test.rs32
1 files changed, 21 insertions, 11 deletions
diff --git a/cli/tools/test.rs b/cli/tools/test.rs
index 8cfad29ee..e3c6507fe 100644
--- a/cli/tools/test.rs
+++ b/cli/tools/test.rs
@@ -13,6 +13,7 @@ use crate::file_watcher::ResolutionResult;
use crate::flags::Flags;
use crate::flags::TestFlags;
use crate::flags::TypeCheckMode;
+use crate::fmt_errors::PrettyJsError;
use crate::fs_util::collect_specifiers;
use crate::fs_util::is_supported_test_ext;
use crate::fs_util::is_supported_test_path;
@@ -31,6 +32,7 @@ use deno_ast::swc::common::comments::CommentKind;
use deno_ast::MediaType;
use deno_core::error::generic_error;
use deno_core::error::AnyError;
+use deno_core::error::JsError;
use deno_core::futures::future;
use deno_core::futures::stream;
use deno_core::futures::FutureExt;
@@ -92,7 +94,7 @@ pub enum TestOutput {
pub enum TestResult {
Ok,
Ignored,
- Failed(String),
+ Failed(Box<JsError>),
}
#[derive(Debug, Clone, PartialEq, Deserialize)]
@@ -108,15 +110,15 @@ pub struct TestStepDescription {
pub enum TestStepResult {
Ok,
Ignored,
- Failed(Option<String>),
- Pending(Option<String>),
+ Failed(Option<Box<JsError>>),
+ Pending(Option<Box<JsError>>),
}
impl TestStepResult {
- fn error(&self) -> Option<&str> {
+ fn error(&self) -> Option<&JsError> {
match self {
- TestStepResult::Failed(Some(text)) => Some(text.as_str()),
- TestStepResult::Pending(Some(text)) => Some(text.as_str()),
+ TestStepResult::Failed(Some(error)) => Some(error),
+ TestStepResult::Pending(Some(error)) => Some(error),
_ => None,
}
}
@@ -154,7 +156,7 @@ pub struct TestSummary {
pub ignored_steps: usize,
pub filtered_out: usize,
pub measured: usize,
- pub failures: Vec<(TestDescription, String)>,
+ pub failures: Vec<(TestDescription, Box<JsError>)>,
}
#[derive(Debug, Clone, Deserialize)]
@@ -294,8 +296,12 @@ impl PrettyTestReporter {
colors::gray(format!("({})", display::human_elapsed(elapsed.into())))
);
- if let Some(error_text) = result.error() {
- for line in error_text.lines() {
+ if let Some(js_error) = result.error() {
+ let err_string = PrettyJsError::create(js_error.clone())
+ .to_string()
+ .trim_start_matches("Uncaught ")
+ .to_string();
+ for line in err_string.lines() {
println!("{}{}", " ".repeat(description.level + 1), line);
}
}
@@ -445,7 +451,7 @@ impl TestReporter for PrettyTestReporter {
fn report_summary(&mut self, summary: &TestSummary, elapsed: &Duration) {
if !summary.failures.is_empty() {
println!("\nfailures:\n");
- for (description, error) in &summary.failures {
+ for (description, js_error) in &summary.failures {
println!(
"{} {} {}",
colors::gray(
@@ -454,7 +460,11 @@ impl TestReporter for PrettyTestReporter {
colors::gray(">"),
description.name
);
- println!("{}", error);
+ let err_string = PrettyJsError::create(*js_error.clone())
+ .to_string()
+ .trim_start_matches("Uncaught ")
+ .to_string();
+ println!("{}", err_string);
println!();
}