Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions cli/args/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ pub struct TestFlags {
pub watch: Option<WatchFlagsWithPaths>,
pub reporter: TestReporterConfig,
pub junit_path: Option<String>,
pub hide_stacktraces: bool,
}

#[derive(Clone, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -2999,6 +3000,12 @@ Directory arguments are expanded to all contained files matching the glob
.value_parser(["pretty", "dot", "junit", "tap"])
.help_heading(TEST_HEADING)
)
.arg(
Arg::new("hide-stacktraces")
.long("hide-stacktraces")
.help("Hide stack traces for errors in failure test results.")
.action(ArgAction::SetTrue)
)
.arg(env_file_arg())
)
}
Expand Down Expand Up @@ -4920,6 +4927,8 @@ fn test_parse(flags: &mut Flags, matches: &mut ArgMatches) {
flags.log_level = Some(Level::Error);
}

let hide_stacktraces = matches.get_flag("hide-stacktraces");

flags.subcommand = DenoSubcommand::Test(TestFlags {
no_run,
doc,
Expand All @@ -4935,6 +4944,7 @@ fn test_parse(flags: &mut Flags, matches: &mut ArgMatches) {
watch: watch_arg_parse_with_paths(matches),
reporter,
junit_path,
hide_stacktraces,
});
}

Expand Down Expand Up @@ -9015,6 +9025,7 @@ mod tests {
watch: Default::default(),
reporter: Default::default(),
junit_path: None,
hide_stacktraces: false,
}),
unstable_config: UnstableConfig {
legacy_flag_enabled: true,
Expand Down Expand Up @@ -9102,6 +9113,7 @@ mod tests {
clean: false,
watch: Default::default(),
junit_path: None,
hide_stacktraces: false,
}),
type_check_mode: TypeCheckMode::Local,
permissions: PermissionFlags {
Expand Down Expand Up @@ -9140,6 +9152,7 @@ mod tests {
watch: Default::default(),
reporter: Default::default(),
junit_path: None,
hide_stacktraces: false,
}),
type_check_mode: TypeCheckMode::Local,
permissions: PermissionFlags {
Expand Down Expand Up @@ -9182,6 +9195,7 @@ mod tests {
watch: Default::default(),
reporter: Default::default(),
junit_path: None,
hide_stacktraces: false,
}),
permissions: PermissionFlags {
no_prompt: true,
Expand Down Expand Up @@ -9318,6 +9332,7 @@ mod tests {
watch: Default::default(),
reporter: Default::default(),
junit_path: None,
hide_stacktraces: false,
}),
permissions: PermissionFlags {
no_prompt: true,
Expand Down Expand Up @@ -9353,6 +9368,7 @@ mod tests {
watch: Some(Default::default()),
reporter: Default::default(),
junit_path: None,
hide_stacktraces: false,
}),
permissions: PermissionFlags {
no_prompt: true,
Expand Down Expand Up @@ -9387,6 +9403,7 @@ mod tests {
watch: Some(Default::default()),
reporter: Default::default(),
junit_path: None,
hide_stacktraces: false,
}),
permissions: PermissionFlags {
no_prompt: true,
Expand Down Expand Up @@ -9428,6 +9445,7 @@ mod tests {
}),
reporter: Default::default(),
junit_path: None,
hide_stacktraces: false,
}),
type_check_mode: TypeCheckMode::Local,
permissions: PermissionFlags {
Expand Down Expand Up @@ -9624,6 +9642,26 @@ mod tests {
);
}

#[test]
fn test_hide_stacktraces() {
let r = flags_from_vec(svec!["deno", "test", "--hide-stacktraces"]);
assert_eq!(
r.unwrap(),
Flags {
subcommand: DenoSubcommand::Test(TestFlags {
hide_stacktraces: true,
..TestFlags::default()
}),
type_check_mode: TypeCheckMode::Local,
permissions: PermissionFlags {
no_prompt: true,
..Default::default()
},
..Flags::default()
}
);
}

#[test]
fn bundle_with_cafile() {
let r = flags_from_vec(svec![
Expand Down
2 changes: 2 additions & 0 deletions cli/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ pub struct WorkspaceTestOptions {
pub trace_leaks: bool,
pub reporter: TestReporterConfig,
pub junit_path: Option<String>,
pub hide_stacktraces: bool,
}

impl WorkspaceTestOptions {
Expand All @@ -394,6 +395,7 @@ impl WorkspaceTestOptions {
trace_leaks: test_flags.trace_leaks,
reporter: test_flags.reporter,
junit_path: test_flags.junit_path.clone(),
hide_stacktraces: test_flags.hide_stacktraces,
}
}
}
Expand Down
13 changes: 10 additions & 3 deletions cli/lsp/testing/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::lsp::logging::lsp_log;
use crate::tools::test;
use crate::tools::test::create_test_event_channel;
use crate::tools::test::FailFastTracker;
use crate::tools::test::TestFailureFormatOptions;

use deno_core::anyhow::anyhow;
use deno_core::error::AnyError;
Expand Down Expand Up @@ -655,7 +656,10 @@ impl LspTestReporter {
let desc = self.tests.get(&desc.id).unwrap();
self.progress(lsp_custom::TestRunProgressMessage::Failed {
test: desc.as_test_identifier(&self.tests),
messages: as_test_messages(failure.to_string(), false),
messages: as_test_messages(
failure.format(&TestFailureFormatOptions::default()),
false,
),
duration: Some(elapsed as u32),
})
}
Expand All @@ -675,7 +679,7 @@ impl LspTestReporter {
let err_string = format!(
"Uncaught error from {}: {}\nThis error was not caught from a test and caused the test runner to fail on the referenced module.\nIt most likely originated from a dangling promise, event/timeout handler or top-level code.",
origin,
test::fmt::format_test_error(js_error)
test::fmt::format_test_error(js_error, &TestFailureFormatOptions::default())
);
let messages = as_test_messages(err_string, false);
for desc in self.tests.values().filter(|d| d.origin() == origin) {
Expand Down Expand Up @@ -751,7 +755,10 @@ impl LspTestReporter {
test::TestStepResult::Failed(failure) => {
self.progress(lsp_custom::TestRunProgressMessage::Failed {
test: desc.as_test_identifier(&self.tests),
messages: as_test_messages(failure.to_string(), false),
messages: as_test_messages(
failure.format(&TestFailureFormatOptions::default()),
false,
),
duration: Some(elapsed as u32),
})
}
Expand Down
8 changes: 6 additions & 2 deletions cli/tools/bench/reporters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use serde::Serialize;

use crate::tools::test::TestFailureFormatOptions;
use crate::version;

use super::*;
Expand Down Expand Up @@ -243,7 +244,10 @@ impl BenchReporter for ConsoleReporter {
&desc.name,
&mitata::reporter::Error {
stack: None,
message: format_test_error(js_error),
message: format_test_error(
js_error,
&TestFailureFormatOptions::default()
),
},
options
)
Expand Down Expand Up @@ -298,7 +302,7 @@ impl BenchReporter for ConsoleReporter {
println!(
"{}: {}",
colors::red_bold("error"),
format_test_error(&error)
format_test_error(&error, &TestFailureFormatOptions::default())
);
println!("This error was not caught from a benchmark and caused the bench runner to fail on the referenced module.");
println!("It most likely originated from a dangling promise, event/timeout handler or top-level code.");
Expand Down
12 changes: 10 additions & 2 deletions cli/tools/jupyter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::tools::repl;
use crate::tools::test::create_single_test_event_channel;
use crate::tools::test::reporters::PrettyTestReporter;
use crate::tools::test::TestEventWorkerSender;
use crate::tools::test::TestFailureFormatOptions;
use crate::CliFactory;
use deno_core::anyhow::bail;
use deno_core::anyhow::Context;
Expand Down Expand Up @@ -142,8 +143,15 @@ pub async fn kernel(
})?;
repl_session.set_test_reporter_factory(Box::new(move || {
Box::new(
PrettyTestReporter::new(false, true, false, true, cwd_url.clone())
.with_writer(Box::new(TestWriter(stdio_tx.clone()))),
PrettyTestReporter::new(
false,
true,
false,
true,
cwd_url.clone(),
TestFailureFormatOptions::default(),
)
.with_writer(Box::new(TestWriter(stdio_tx.clone()))),
)
}));

Expand Down
2 changes: 2 additions & 0 deletions cli/tools/repl/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::tools::test::send_test_event;
use crate::tools::test::worker_has_tests;
use crate::tools::test::TestEvent;
use crate::tools::test::TestEventReceiver;
use crate::tools::test::TestFailureFormatOptions;

use deno_ast::diagnostics::Diagnostic;
use deno_ast::swc::ast as swc_ast;
Expand Down Expand Up @@ -276,6 +277,7 @@ impl ReplSession {
false,
true,
cwd_url.clone(),
TestFailureFormatOptions::default(),
))
}),
main_module,
Expand Down
10 changes: 9 additions & 1 deletion cli/tools/test/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,24 @@ fn abbreviate_test_error(js_error: &JsError) -> JsError {
// This function prettifies `JsError` and applies some changes specifically for
// test runner purposes:
//
// - hide stack traces if `options.hide_stacktraces` is set to `true`
//
// - 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 {
pub fn format_test_error(
js_error: &JsError,
options: &TestFailureFormatOptions,
) -> String {
let mut js_error = abbreviate_test_error(js_error);
js_error.exception_message = js_error
.exception_message
.trim_start_matches("Uncaught ")
.to_string();
if options.hide_stacktraces {
return js_error.exception_message;
}
format_js_error(&js_error)
}

Expand Down
Loading