summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-04-01 18:58:52 -0400
committerGitHub <noreply@github.com>2024-04-01 18:58:52 -0400
commitb0c1bd82a85ddb54ffe717a2c158c33c0be99fe8 (patch)
tree111cefee08d16935f2bab467db0328e670c14243 /tests
parent240b362c002d17bc2b676673ed1b9406683ff0c2 (diff)
fix: prevent cache db errors when deno_dir not exists (#23168)
Closes #20202
Diffstat (limited to 'tests')
-rw-r--r--tests/specs/fmt/no_error_deno_dir_not_exists/__test__.jsonc8
-rw-r--r--tests/specs/fmt/no_error_deno_dir_not_exists/fmt.out2
-rw-r--r--tests/specs/fmt/no_error_deno_dir_not_exists/main.ts1
-rw-r--r--tests/specs/mod.rs7
-rw-r--r--tests/util/server/src/builders.rs7
-rw-r--r--tests/util/server/src/fs.rs6
6 files changed, 27 insertions, 4 deletions
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<RefCell<Vec<u8>>>) {
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<String>,
+ #[serde(default)]
+ pub envs: HashMap<String, String>,
pub steps: Vec<StepMetaData>,
}
@@ -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<str>) {
- fs::write(self, text.as_ref()).unwrap();
+ pub fn write(&self, text: impl AsRef<[u8]>) {
+ fs::write(self, text).unwrap();
}
pub fn write_json<TValue: Serialize>(&self, value: &TValue) {
@@ -461,7 +461,7 @@ impl TempDir {
self.target_path().join(from).rename(to)
}
- pub fn write(&self, path: impl AsRef<Path>, text: impl AsRef<str>) {
+ pub fn write(&self, path: impl AsRef<Path>, text: impl AsRef<[u8]>) {
self.target_path().join(path).write(text)
}