From b0c1bd82a85ddb54ffe717a2c158c33c0be99fe8 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 1 Apr 2024 18:58:52 -0400 Subject: fix: prevent cache db errors when deno_dir not exists (#23168) Closes #20202 --- tests/specs/fmt/no_error_deno_dir_not_exists/__test__.jsonc | 8 ++++++++ tests/specs/fmt/no_error_deno_dir_not_exists/fmt.out | 2 ++ tests/specs/fmt/no_error_deno_dir_not_exists/main.ts | 1 + tests/specs/mod.rs | 7 ++++++- tests/util/server/src/builders.rs | 7 +++++++ tests/util/server/src/fs.rs | 6 +++--- 6 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 tests/specs/fmt/no_error_deno_dir_not_exists/__test__.jsonc create mode 100644 tests/specs/fmt/no_error_deno_dir_not_exists/fmt.out create mode 100644 tests/specs/fmt/no_error_deno_dir_not_exists/main.ts (limited to 'tests') diff --git a/tests/specs/fmt/no_error_deno_dir_not_exists/__test__.jsonc b/tests/specs/fmt/no_error_deno_dir_not_exists/__test__.jsonc new file mode 100644 index 000000000..4e4f67477 --- /dev/null +++ b/tests/specs/fmt/no_error_deno_dir_not_exists/__test__.jsonc @@ -0,0 +1,8 @@ +{ + "tempDir": true, + "envs": { + "DENO_DIR": "$DENO_DIR/not_exists" + }, + "args": "fmt --log-level=debug main.ts", + "output": "fmt.out" +} diff --git a/tests/specs/fmt/no_error_deno_dir_not_exists/fmt.out b/tests/specs/fmt/no_error_deno_dir_not_exists/fmt.out new file mode 100644 index 000000000..930bcb5c6 --- /dev/null +++ b/tests/specs/fmt/no_error_deno_dir_not_exists/fmt.out @@ -0,0 +1,2 @@ +[WILDCARD]Created parent directory for cache db.[WILDCARD] +Checked 1 file diff --git a/tests/specs/fmt/no_error_deno_dir_not_exists/main.ts b/tests/specs/fmt/no_error_deno_dir_not_exists/main.ts new file mode 100644 index 000000000..296d5492b --- /dev/null +++ b/tests/specs/fmt/no_error_deno_dir_not_exists/main.ts @@ -0,0 +1 @@ +console.log(1); diff --git a/tests/specs/mod.rs b/tests/specs/mod.rs index 3eb8bb386..17263b8b9 100644 --- a/tests/specs/mod.rs +++ b/tests/specs/mod.rs @@ -128,7 +128,9 @@ fn run_test(test: &Test, diagnostic_logger: Rc>>) { context.deno_dir().path().remove_dir_all(); } - let command = context.new_command().envs(&step.envs); + let command = context + .new_command() + .envs(metadata.envs.iter().chain(step.envs.iter())); let command = match &step.args { VecOrString::Vec(args) => command.args_vec(args), VecOrString::String(text) => command.args(text), @@ -166,6 +168,8 @@ struct MultiTestMetaData { /// The base environment to use for the test. #[serde(default)] pub base: Option, + #[serde(default)] + pub envs: HashMap, pub steps: Vec, } @@ -185,6 +189,7 @@ impl SingleTestMetaData { MultiTestMetaData { base: self.base, temp_dir: self.temp_dir, + envs: Default::default(), steps: vec![self.step], } } diff --git a/tests/util/server/src/builders.rs b/tests/util/server/src/builders.rs index e1d351da8..6a57548a3 100644 --- a/tests/util/server/src/builders.rs +++ b/tests/util/server/src/builders.rs @@ -782,6 +782,13 @@ impl TestCommandBuilder { for key in &self.envs_remove { envs.remove(key); } + + // update any test variables in the env value + for value in envs.values_mut() { + *value = + value.replace("$DENO_DIR", &self.deno_dir.path().to_string_lossy()); + } + envs } } diff --git a/tests/util/server/src/fs.rs b/tests/util/server/src/fs.rs index 8955dc30e..b9ae81b49 100644 --- a/tests/util/server/src/fs.rs +++ b/tests/util/server/src/fs.rs @@ -159,8 +159,8 @@ impl PathRef { file.write_all(text.as_ref().as_bytes()).unwrap(); } - pub fn write(&self, text: impl AsRef) { - fs::write(self, text.as_ref()).unwrap(); + pub fn write(&self, text: impl AsRef<[u8]>) { + fs::write(self, text).unwrap(); } pub fn write_json(&self, value: &TValue) { @@ -461,7 +461,7 @@ impl TempDir { self.target_path().join(from).rename(to) } - pub fn write(&self, path: impl AsRef, text: impl AsRef) { + pub fn write(&self, path: impl AsRef, text: impl AsRef<[u8]>) { self.target_path().join(path).write(text) } -- cgit v1.2.3