From 244926e83c7d3cae3c3ae3fc14e996e3066da43e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 15 Apr 2022 14:24:41 +0200 Subject: feat(test): format user code output (#14271) This commit changes "deno test" to better denote user output coming from test cases. This is done by printing "---- output ----" and "---- output end ----" markers if an output is produced. The output from "console" and "Deno.core.print" is captured, as well as direct writes to "Deno.stdout" and "Deno.stderr". To achieve that new APIs were added to "deno_core" crate, that allow to replace an existing resource with a different one (while keeping resource ids intact). Resources for stdout and stderr are replaced by pipes. Co-authored-by: David Sherret --- cli/lsp/testing/execution.rs | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'cli/lsp/testing/execution.rs') diff --git a/cli/lsp/testing/execution.rs b/cli/lsp/testing/execution.rs index dcf980fd6..bc780a475 100644 --- a/cli/lsp/testing/execution.rs +++ b/cli/lsp/testing/execution.rs @@ -14,6 +14,7 @@ use crate::lsp::client::TestingNotification; use crate::lsp::config; use crate::lsp::logging::lsp_log; use crate::ops; +use crate::ops::testing::create_stdout_stderr_pipes; use crate::proc_state; use crate::tools::test; @@ -183,11 +184,17 @@ async fn test_specifier( options: Option, ) -> Result<(), AnyError> { if !token.is_cancelled() { + let (stdout_writer, stderr_writer) = + create_stdout_stderr_pipes(channel.clone()); let mut worker = create_main_worker( &ps, specifier.clone(), permissions, - vec![ops::testing::init(channel.clone())], + vec![ops::testing::init( + channel.clone(), + stdout_writer, + stderr_writer, + )], ); worker @@ -752,16 +759,20 @@ impl test::TestReporter for LspTestReporter { .get(origin) .and_then(|v| v.last().map(|td| td.into())) }); - match output { - test::TestOutput::Console(value) => { - self.progress(lsp_custom::TestRunProgressMessage::Output { - value: value.replace('\n', "\r\n"), - test, - // TODO(@kitsonk) test output should include a location - location: None, - }) + let value = match output { + test::TestOutput::PrintStdout(value) + | test::TestOutput::PrintStderr(value) => value.replace('\n', "\r\n"), + test::TestOutput::Stdout(bytes) | test::TestOutput::Stderr(bytes) => { + String::from_utf8_lossy(bytes).replace('\n', "\r\n") } - } + }; + + self.progress(lsp_custom::TestRunProgressMessage::Output { + value, + test, + // TODO(@kitsonk) test output should include a location + location: None, + }) } fn report_result( -- cgit v1.2.3