diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-06-09 08:40:10 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-09 08:40:10 -0400 |
commit | f182c8af872a429d82c96a5ef091cec0e4e75102 (patch) | |
tree | 50fe326d0378b1c73fca105aeb73b00eafe51723 /test_util/src/builders.rs | |
parent | 168eb8e01d3cdbd6358e11cf399fbf4ef1db358b (diff) |
chore(tests): add `.use_symlinked_temp_dir()` to `TestBuilder` (#19435)
This allows easily using a symlinked temporary directory, which is
useful for debugging issues locally that happen on the CI with a
symlinked temporary directory. For example:
```rs
let context = TestContextBuilder::new()
.use_temp_cwd()
.use_symlinked_temp_dir() // add this
.build();
```
Diffstat (limited to 'test_util/src/builders.rs')
-rw-r--r-- | test_util/src/builders.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test_util/src/builders.rs b/test_util/src/builders.rs index a000e5bcd..049ccbd67 100644 --- a/test_util/src/builders.rs +++ b/test_util/src/builders.rs @@ -31,6 +31,7 @@ pub struct TestContextBuilder { use_http_server: bool, use_temp_cwd: bool, use_separate_deno_dir: bool, + use_symlinked_temp_dir: bool, /// Copies the files at the specified directory in the "testdata" directory /// to the temp folder and runs the test from there. This is useful when /// the test creates files in the testdata directory (ex. a node_modules folder) @@ -59,6 +60,18 @@ impl TestContextBuilder { self } + /// Causes the temp directory to be symlinked to a target directory + /// which is useful for debugging issues that only show up on the CI. + /// + /// Note: This method is not actually deprecated, it's just the CI + /// does this by default so there's no need to check in any code that + /// uses this into the repo. This is just for debugging purposes. + #[deprecated] + pub fn use_symlinked_temp_dir(mut self) -> Self { + self.use_symlinked_temp_dir = true; + self + } + /// By default, the temp_dir and the deno_dir will be shared. /// In some cases, that might cause an issue though, so calling /// this will use a separate directory for the deno dir and the @@ -110,6 +123,11 @@ impl TestContextBuilder { } else { deno_dir.clone() }; + let temp_dir = if self.use_symlinked_temp_dir { + TempDir::new_symlinked(temp_dir) + } else { + temp_dir + }; let testdata_dir = if let Some(temp_copy_dir) = &self.copy_temp_dir { let test_data_path = testdata_path().join(temp_copy_dir); let temp_copy_dir = temp_dir.path().join(temp_copy_dir); |