Skip to content

Commit

Permalink
chore: provide error message when a deno.json will be auto-discovered…
Browse files Browse the repository at this point in the history
… by the test suite (denoland#21315)
  • Loading branch information
dsherret authored Nov 23, 2023
1 parent d8961a9 commit aadd369
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 35 additions & 0 deletions test_util/src/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<String>> =
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,
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion test_util/src/pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
}

Expand Down

0 comments on commit aadd369

Please sign in to comment.