diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-08-01 20:49:09 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-02 00:49:09 +0000 |
commit | 1cefa831fd74b14121494045a347024502d74e34 (patch) | |
tree | cc7791cf674e427fe4165262db416e6c537e99a3 /test_util/src | |
parent | 36ae37604a0ddab4349df6eb6fafb8ae39fd20fc (diff) |
feat(unstable): optional `deno_modules` directory (#19977)
Closes #15633
Diffstat (limited to 'test_util/src')
-rw-r--r-- | test_util/src/builders.rs | 23 | ||||
-rw-r--r-- | test_util/src/fs.rs | 4 |
2 files changed, 15 insertions, 12 deletions
diff --git a/test_util/src/builders.rs b/test_util/src/builders.rs index f9c546c6f..8811efa02 100644 --- a/test_util/src/builders.rs +++ b/test_util/src/builders.rs @@ -123,15 +123,13 @@ impl TestContextBuilder { } else { temp_dir }; - let testdata_dir = if let Some(temp_copy_dir) = &self.copy_temp_dir { - let test_data_path = PathRef::new(testdata_path()).join(temp_copy_dir); + let testdata_dir = testdata_path(); + if let Some(temp_copy_dir) = &self.copy_temp_dir { + let test_data_path = testdata_dir.join(temp_copy_dir); let temp_copy_dir = temp_dir.path().join(temp_copy_dir); temp_copy_dir.create_dir_all(); test_data_path.copy_to_recursive(&temp_copy_dir); - temp_dir.path().clone() - } else { - PathRef::new(testdata_path()) - }; + } let deno_exe = self.deno_exe.clone().unwrap_or_else(deno_exe_path); println!("deno_exe path {}", deno_exe); @@ -146,7 +144,7 @@ impl TestContextBuilder { cwd: self.cwd.clone(), deno_exe, envs: self.envs.clone(), - use_temp_cwd: self.use_temp_cwd, + use_temp_cwd: self.use_temp_cwd || self.copy_temp_dir.is_some(), _http_server_guard: http_server_guard, deno_dir, temp_dir, @@ -279,14 +277,15 @@ impl TestCommandBuilder { } fn build_cwd(&self) -> PathRef { - let cwd = self.cwd.as_ref().or(self.context.cwd.as_ref()); - if self.context.use_temp_cwd { - assert!(cwd.is_none()); + let root_dir = if self.context.use_temp_cwd { self.context.temp_dir.path().to_owned() - } else if let Some(cwd_) = cwd { - self.context.testdata_dir.join(cwd_) } else { self.context.testdata_dir.clone() + }; + let specified_cwd = self.cwd.as_ref().or(self.context.cwd.as_ref()); + match specified_cwd { + Some(cwd) => root_dir.join(cwd), + None => root_dir, } } diff --git a/test_util/src/fs.rs b/test_util/src/fs.rs index 005c467a6..57ab8ee10 100644 --- a/test_util/src/fs.rs +++ b/test_util/src/fs.rs @@ -116,6 +116,10 @@ impl PathRef { serde_json::from_str(&self.read_to_string()).unwrap() } + pub fn read_json_value(&self) -> serde_json::Value { + serde_json::from_str(&self.read_to_string()).unwrap() + } + pub fn rename(&self, to: impl AsRef<Path>) { fs::rename(self, self.join(to)).unwrap(); } |