Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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 @@ -344,6 +344,7 @@ pub struct TestFlags {
pub watch: Option<WatchFlags>,
pub reporter: TestReporterConfig,
pub junit_path: Option<String>,
pub hide_traces: bool,
}

#[derive(Clone, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -2683,6 +2684,12 @@ Note: running multiple `deno test --clean` calls in series or parallel for the s
.help("Select reporter to use. Default to 'pretty'.")
.value_parser(["pretty", "dot", "junit", "tap"])
)
.arg(
Arg::new("hide-traces")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rename this option to --hide-stacktraces?

.long("hide-traces")
.help("Hide stack traces for errors in failure test results.")
.action(ArgAction::SetTrue)
)
.arg(env_file_arg())
)
}
Expand Down Expand Up @@ -4331,6 +4338,8 @@ fn test_parse(flags: &mut Flags, matches: &mut ArgMatches) {
flags.log_level = Some(Level::Error);
}

let hide_traces = matches.get_flag("hide-traces");

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

Expand Down Expand Up @@ -8222,6 +8232,7 @@ mod tests {
watch: Default::default(),
reporter: Default::default(),
junit_path: None,
hide_traces: false,
}),
unstable_config: UnstableConfig {
legacy_flag_enabled: true,
Expand Down Expand Up @@ -8309,6 +8320,7 @@ mod tests {
clean: false,
watch: Default::default(),
junit_path: None,
hide_traces: false,
}),
type_check_mode: TypeCheckMode::Local,
permissions: PermissionFlags {
Expand Down Expand Up @@ -8347,6 +8359,7 @@ mod tests {
watch: Default::default(),
reporter: Default::default(),
junit_path: None,
hide_traces: false,
}),
type_check_mode: TypeCheckMode::Local,
permissions: PermissionFlags {
Expand Down Expand Up @@ -8389,6 +8402,7 @@ mod tests {
watch: Default::default(),
reporter: Default::default(),
junit_path: None,
hide_traces: false,
}),
permissions: PermissionFlags {
no_prompt: true,
Expand Down Expand Up @@ -8525,6 +8539,7 @@ mod tests {
watch: Default::default(),
reporter: Default::default(),
junit_path: None,
hide_traces: false,
}),
permissions: PermissionFlags {
no_prompt: true,
Expand Down Expand Up @@ -8560,6 +8575,7 @@ mod tests {
watch: Some(Default::default()),
reporter: Default::default(),
junit_path: None,
hide_traces: false,
}),
permissions: PermissionFlags {
no_prompt: true,
Expand Down Expand Up @@ -8594,6 +8610,7 @@ mod tests {
watch: Some(Default::default()),
reporter: Default::default(),
junit_path: None,
hide_traces: false,
}),
permissions: PermissionFlags {
no_prompt: true,
Expand Down Expand Up @@ -8634,6 +8651,7 @@ mod tests {
}),
reporter: Default::default(),
junit_path: None,
hide_traces: false,
}),
type_check_mode: TypeCheckMode::Local,
permissions: PermissionFlags {
Expand Down Expand Up @@ -8665,6 +8683,26 @@ mod tests {
);
}

#[test]
fn test_hide_traces() {
let r = flags_from_vec(svec!["deno", "test", "--hide-traces"]);
assert_eq!(
r.unwrap(),
Flags {
subcommand: DenoSubcommand::Test(TestFlags {
hide_traces: 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 @@ -372,6 +372,7 @@ pub struct TestOptions {
pub trace_leaks: bool,
pub reporter: TestReporterConfig,
pub junit_path: Option<String>,
pub hide_traces: bool,
}

impl TestOptions {
Expand Down Expand Up @@ -400,6 +401,7 @@ impl TestOptions {
trace_leaks: test_flags.trace_leaks,
reporter: test_flags.reporter,
junit_path: test_flags.junit_path,
hide_traces: test_flags.hide_traces,
})
}
}
Expand Down
6 changes: 3 additions & 3 deletions cli/lsp/testing/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ 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(None), false),
duration: Some(elapsed as u32),
})
}
Expand All @@ -674,7 +674,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, None)
);
let messages = as_test_messages(err_string, false);
for desc in self.tests.values().filter(|d| d.origin() == origin) {
Expand Down Expand Up @@ -750,7 +750,7 @@ 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(None), false),
duration: Some(elapsed as u32),
})
}
Expand Down
4 changes: 2 additions & 2 deletions cli/tools/bench/reporters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl BenchReporter for ConsoleReporter {
&desc.name,
&mitata::reporter::Error {
stack: None,
message: format_test_error(js_error),
message: format_test_error(js_error, None),
},
options
)
Expand Down Expand Up @@ -292,7 +292,7 @@ impl BenchReporter for ConsoleReporter {
println!(
"{}: {}",
colors::red_bold("error"),
format_test_error(&error)
format_test_error(&error, None)
);
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
1 change: 1 addition & 0 deletions cli/tools/repl/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ impl ReplSession {
let report_tests_handle = spawn(report_tests(
self.test_event_receiver.take().unwrap(),
(self.test_reporter_factory)(),
None,
));
run_tests_for_worker(
&mut self.worker,
Expand Down
12 changes: 11 additions & 1 deletion cli/tools/test/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,26 @@ 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_traces` 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: Option<&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 let Some(options) = options {
if options.hide_traces {
return js_error.exception_message;
}
}
format_js_error(&js_error)
}

Expand Down
Loading