From 5f2d9a4a220307b1111c91dfac74951ef3925457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sat, 16 Apr 2022 19:51:12 +0200 Subject: 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). --- cli/lsp/testing/execution.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'cli/lsp/testing') diff --git a/cli/lsp/testing/execution.rs b/cli/lsp/testing/execution.rs index bc780a475..b305b1650 100644 --- a/cli/lsp/testing/execution.rs +++ b/cli/lsp/testing/execution.rs @@ -8,6 +8,7 @@ use crate::checksum; use crate::create_main_worker; use crate::emit; use crate::flags; +use crate::fmt_errors::PrettyJsError; use crate::located_script_name; use crate::lsp::client::Client; use crate::lsp::client::TestingNotification; @@ -797,10 +798,14 @@ impl test::TestReporter for LspTestReporter { test: desc.into(), }) } - test::TestResult::Failed(message) => { + test::TestResult::Failed(js_error) => { + let err_string = PrettyJsError::create(*js_error.clone()) + .to_string() + .trim_start_matches("Uncaught ") + .to_string(); self.progress(lsp_custom::TestRunProgressMessage::Failed { test: desc.into(), - messages: as_test_messages(message, false), + messages: as_test_messages(err_string, false), duration: Some(elapsed as u32), }) } @@ -839,9 +844,13 @@ impl test::TestReporter for LspTestReporter { test: desc.into(), }) } - test::TestStepResult::Failed(message) => { - let messages = if let Some(message) = message { - as_test_messages(message, false) + test::TestStepResult::Failed(js_error) => { + let messages = if let Some(js_error) = js_error { + let err_string = PrettyJsError::create(*js_error.clone()) + .to_string() + .trim_start_matches("Uncaught ") + .to_string(); + as_test_messages(err_string, false) } else { vec![] }; -- cgit v1.2.3