From aadd369589cbc31779ab551274e7952405570be3 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 23 Nov 2023 14:24:30 -0500 Subject: chore: provide error message when a deno.json will be auto-discovered by the test suite (#21315) --- test_util/src/builders.rs | 35 +++++++++++++++++++++++++++++++++++ test_util/src/pty.rs | 2 +- 2 files changed, 36 insertions(+), 1 deletion(-) (limited to 'test_util/src') diff --git a/test_util/src/builders.rs b/test_util/src/builders.rs index 80459af06..c356ab16a 100644 --- a/test_util/src/builders.rs +++ b/test_util/src/builders.rs @@ -32,6 +32,37 @@ use crate::testdata_path; use crate::HttpServerGuard; use crate::TempDir; +// Gives the developer a nice error message if they have a deno configuration +// file that will be auto-discovered by the tests and cause a lot of failures. +static HAS_DENO_JSON_IN_WORKING_DIR_ERR: once_cell::sync::Lazy> = + once_cell::sync::Lazy::new(|| { + let testdata_path = testdata_path(); + let mut current_dir = testdata_path.as_path(); + let deno_json_names = ["deno.json", "deno.jsonc"]; + loop { + for name in deno_json_names { + let deno_json_path = current_dir.join(name); + if deno_json_path.exists() { + return Some(format!( + concat!( + "Found deno configuration file at {}. The test suite relies on ", + "a deno.json not existing in any ancestor directory. Please ", + "delete this file so the tests won't auto-discover it.", + ), + deno_json_path.display(), + )); + } + } + if let Some(parent) = current_dir.parent() { + current_dir = parent; + } else { + break; + } + } + + None + }); + #[derive(Default)] pub struct TestContextBuilder { use_http_server: bool, @@ -121,6 +152,10 @@ impl TestContextBuilder { } pub fn build(&self) -> TestContext { + if let Some(err) = &*HAS_DENO_JSON_IN_WORKING_DIR_ERR { + panic!("{}", err); + } + let temp_dir_path = self .temp_dir_path .clone() diff --git a/test_util/src/pty.rs b/test_util/src/pty.rs index 020e5b5fa..b9f9dfc8b 100644 --- a/test_util/src/pty.rs +++ b/test_util/src/pty.rs @@ -45,7 +45,7 @@ impl Pty { .contains("exit using ctrl+d, ctrl+c, or close()") }, // it sometimes takes a while to startup on the CI, so use a longer timeout - Duration::from_secs(30), + Duration::from_secs(60), ); } -- cgit v1.2.3