summaryrefslogtreecommitdiff
path: root/cli/tools/test_runner.rs
diff options
context:
space:
mode:
authorCasper Beyer <caspervonb@pm.me>2021-07-22 19:34:29 +0800
committerGitHub <noreply@github.com>2021-07-22 13:34:29 +0200
commit4861b13aabd61d2df600e79a2e621fa1f3b870c3 (patch)
tree8cb7d995f236425ee825491f79ab6189d9a93b9b /cli/tools/test_runner.rs
parent78fc9a4c600d28bf4c899695076f0bce159fb7a6 (diff)
fix(cli): normalize test command errors (#11375)
Diffstat (limited to 'cli/tools/test_runner.rs')
-rw-r--r--cli/tools/test_runner.rs52
1 files changed, 32 insertions, 20 deletions
diff --git a/cli/tools/test_runner.rs b/cli/tools/test_runner.rs
index 39d6bd62b..b185e3361 100644
--- a/cli/tools/test_runner.rs
+++ b/cli/tools/test_runner.rs
@@ -11,6 +11,7 @@ use crate::module_graph;
use crate::program_state::ProgramState;
use crate::tokio_util;
use crate::tools::coverage::CoverageCollector;
+use deno_core::error::generic_error;
use deno_core::error::AnyError;
use deno_core::futures::future;
use deno_core::futures::stream;
@@ -320,7 +321,6 @@ pub async fn run_test_file(
/// Runs tests.
///
-/// Returns a boolean indicating whether the tests failed.
#[allow(clippy::too_many_arguments)]
pub async fn run_tests(
program_state: Arc<ProgramState>,
@@ -335,7 +335,11 @@ pub async fn run_tests(
filter: Option<String>,
shuffle: Option<u64>,
concurrent_jobs: usize,
-) -> Result<bool, AnyError> {
+) -> Result<(), AnyError> {
+ if !allow_none && doc_modules.is_empty() && test_modules.is_empty() {
+ return Err(generic_error("No test modules found"));
+ }
+
let test_modules = if let Some(seed) = shuffle {
let mut rng = SmallRng::seed_from_u64(seed);
let mut test_modules = test_modules.clone();
@@ -423,13 +427,6 @@ pub async fn run_tests(
program_state.maybe_import_map.clone(),
)
.await?;
- } else if test_modules.is_empty() {
- println!("No matching test modules found");
- if !allow_none {
- std::process::exit(1);
- }
-
- return Ok(false);
}
program_state
@@ -443,7 +440,7 @@ pub async fn run_tests(
.await?;
if no_run {
- return Ok(false);
+ return Ok(());
}
// Because scripts, and therefore worker.execute cannot detect unresolved promises at the moment
@@ -493,7 +490,7 @@ pub async fn run_tests(
})
});
- let join_futures = stream::iter(join_handles)
+ let join_stream = stream::iter(join_handles)
.buffer_unordered(concurrent_jobs)
.collect::<Vec<Result<Result<(), AnyError>, tokio::task::JoinError>>>();
@@ -552,17 +549,20 @@ pub async fn run_tests(
reporter.report_summary(&summary, &elapsed);
if used_only {
- println!(
- "{} because the \"only\" option was used\n",
- colors::red("FAILED")
- );
+ return Err(generic_error(
+ "Test failed because the \"only\" option was used",
+ ));
+ }
+
+ if summary.failed > 0 {
+ return Err(generic_error("Test failed"));
}
- used_only || summary.failed > 0
+ Ok(())
})
};
- let (result, join_results) = future::join(handler, join_futures).await;
+ let (join_results, result) = future::join(join_stream, handler).await;
let mut join_errors = join_results.into_iter().filter_map(|join_result| {
join_result
@@ -572,10 +572,22 @@ pub async fn run_tests(
});
if let Some(e) = join_errors.next() {
- Err(e)
- } else {
- Ok(result.unwrap_or(false))
+ return Err(e);
}
+
+ match result {
+ Ok(result) => {
+ if let Some(err) = result.err() {
+ return Err(err);
+ }
+ }
+
+ Err(err) => {
+ return Err(err.into());
+ }
+ }
+
+ Ok(())
}
#[cfg(test)]