diff options
Diffstat (limited to 'cli/tools')
-rw-r--r-- | cli/tools/test.rs | 70 |
1 files changed, 61 insertions, 9 deletions
diff --git a/cli/tools/test.rs b/cli/tools/test.rs index 96e0dd8c3..aab062a6c 100644 --- a/cli/tools/test.rs +++ b/cli/tools/test.rs @@ -301,10 +301,7 @@ impl PrettyTestReporter { ); if let Some(js_error) = result.error() { - let err_string = PrettyJsError::create(js_error.clone()) - .to_string() - .trim_start_matches("Uncaught ") - .to_string(); + let err_string = format_test_error(js_error); for line in err_string.lines() { println!("{}{}", " ".repeat(description.level + 1), line); } @@ -464,11 +461,7 @@ impl TestReporter for PrettyTestReporter { colors::gray(">"), description.name ); - let err_string = PrettyJsError::create(*js_error.clone()) - .to_string() - .trim_start_matches("Uncaught ") - .to_string(); - println!("{}", err_string); + println!("{}", format_test_error(js_error)); println!(); } @@ -525,6 +518,65 @@ impl TestReporter for PrettyTestReporter { } } +fn abbreviate_test_error(js_error: &JsError) -> JsError { + let mut js_error = js_error.clone(); + let frames = std::mem::take(&mut js_error.frames); + + // check if there are any stack frames coming from user code + let should_filter = frames.iter().any(|f| { + if let Some(file_name) = &f.file_name { + !(file_name.starts_with("[deno:") || file_name.starts_with("deno:")) + } else { + true + } + }); + + if should_filter { + let mut frames = frames + .into_iter() + .rev() + .skip_while(|f| { + if let Some(file_name) = &f.file_name { + file_name.starts_with("[deno:") || file_name.starts_with("deno:") + } else { + false + } + }) + .into_iter() + .collect::<Vec<_>>(); + frames.reverse(); + js_error.frames = frames; + } else { + js_error.frames = frames; + } + + js_error.cause = js_error + .cause + .as_ref() + .map(|e| Box::new(abbreviate_test_error(e))); + js_error.aggregated = js_error + .aggregated + .as_ref() + .map(|es| es.iter().map(abbreviate_test_error).collect()); + js_error +} + +// This function maps JsError to PrettyJsError and applies some changes +// specifically for test runner purposes: +// +// - filter out stack frames: +// - if stack trace consists of mixed user and internal code, the frames +// below the first user code frame are filtered out +// - if stack trace consists only of internal code it is preserved as is +pub fn format_test_error(js_error: &JsError) -> String { + let mut js_error = abbreviate_test_error(js_error); + js_error.exception_message = js_error + .exception_message + .trim_start_matches("Uncaught ") + .to_string(); + PrettyJsError::create(js_error).to_string() +} + fn create_reporter( concurrent: bool, echo_output: bool, |