diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-03-13 14:18:29 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-13 18:18:29 +0000 |
commit | 44b0d4cb11853bcdc7aa61c1412719a13d572b24 (patch) | |
tree | 074bcf6b77b4174343c4d0f3c239c53b7adf8350 /test_util/src | |
parent | e8f22c076525c2fa55115349157f67085df287bf (diff) |
fix(npm): show a progress bar when initializing the node_modules folder (#18136)
Creating the node_modules folder when the packages are already
downloaded can take a bit of time and not knowing what is going on can
be confusing. It's better to show a progress bar.
Diffstat (limited to 'test_util/src')
-rw-r--r-- | test_util/src/builders.rs | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/test_util/src/builders.rs b/test_util/src/builders.rs index e72ce9b63..9b300b911 100644 --- a/test_util/src/builders.rs +++ b/test_util/src/builders.rs @@ -30,6 +30,7 @@ use crate::TempDir; pub struct TestContextBuilder { use_http_server: bool, use_temp_cwd: bool, + use_separate_deno_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) @@ -60,6 +61,15 @@ impl TestContextBuilder { 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 + /// temp directory. + pub fn use_separate_deno_dir(&mut self) -> &mut Self { + self.use_separate_deno_dir = true; + self + } + /// 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) @@ -102,12 +112,17 @@ impl TestContextBuilder { pub fn build(&self) -> TestContext { let deno_dir = new_deno_dir(); // keep this alive for the test + let temp_dir = if self.use_separate_deno_dir { + TempDir::new() + } else { + deno_dir.clone() + }; 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 = deno_dir.path().join(temp_copy_dir); + let temp_copy_dir = temp_dir.path().join(temp_copy_dir); std::fs::create_dir_all(&temp_copy_dir).unwrap(); copy_dir_recursive(&test_data_path, &temp_copy_dir).unwrap(); - deno_dir.path().to_owned() + temp_dir.path().to_owned() } else { testdata_path() }; @@ -128,6 +143,7 @@ impl TestContextBuilder { use_temp_cwd: self.use_temp_cwd, _http_server_guard: http_server_guard, deno_dir, + temp_dir, testdata_dir, } } @@ -141,6 +157,7 @@ pub struct TestContext { cwd: Option<String>, _http_server_guard: Option<Rc<HttpServerGuard>>, deno_dir: TempDir, + temp_dir: TempDir, testdata_dir: PathBuf, } @@ -163,6 +180,10 @@ impl TestContext { &self.deno_dir } + pub fn temp_dir(&self) -> &TempDir { + &self.temp_dir + } + pub fn new_command(&self) -> TestCommandBuilder { TestCommandBuilder { command_name: self.deno_exe.to_string_lossy().to_string(), @@ -268,7 +289,7 @@ impl TestCommandBuilder { let cwd = self.cwd.as_ref().or(self.context.cwd.as_ref()); let cwd = if self.context.use_temp_cwd { assert!(cwd.is_none()); - self.context.deno_dir.path().to_owned() + self.context.temp_dir.path().to_owned() } else if let Some(cwd_) = cwd { self.context.testdata_dir.join(cwd_) } else { |