mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -05:00
dont use env vars in multiple installer tests (#3967)
This commit is contained in:
parent
a7056095a5
commit
63718ab305
1 changed files with 8 additions and 16 deletions
|
@ -204,6 +204,10 @@ mod tests {
|
||||||
fn install_basic() {
|
fn install_basic() {
|
||||||
let temp_dir = TempDir::new().expect("tempdir fail");
|
let temp_dir = TempDir::new().expect("tempdir fail");
|
||||||
let temp_dir_str = temp_dir.path().to_string_lossy().to_string();
|
let temp_dir_str = temp_dir.path().to_string_lossy().to_string();
|
||||||
|
// NOTE: this test overrides environmental variables
|
||||||
|
// don't add other tests in this file that mess with "HOME" and "USEPROFILE"
|
||||||
|
// otherwise transient failures are possible because tests are run in parallel.
|
||||||
|
// It means that other test can override env vars when this test is running.
|
||||||
let original_home = env::var_os("HOME");
|
let original_home = env::var_os("HOME");
|
||||||
let original_user_profile = env::var_os("HOME");
|
let original_user_profile = env::var_os("HOME");
|
||||||
env::set_var("HOME", &temp_dir_str);
|
env::set_var("HOME", &temp_dir_str);
|
||||||
|
@ -322,15 +326,10 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn install_force() {
|
fn install_force() {
|
||||||
let temp_dir = TempDir::new().expect("tempdir fail");
|
let temp_dir = TempDir::new().expect("tempdir fail");
|
||||||
let temp_dir_str = temp_dir.path().to_string_lossy().to_string();
|
|
||||||
let original_home = env::var_os("HOME");
|
|
||||||
let original_user_profile = env::var_os("HOME");
|
|
||||||
env::set_var("HOME", &temp_dir_str);
|
|
||||||
env::set_var("USERPROFILE", &temp_dir_str);
|
|
||||||
|
|
||||||
install(
|
install(
|
||||||
DenoFlags::default(),
|
DenoFlags::default(),
|
||||||
None,
|
Some(temp_dir.path().to_path_buf()),
|
||||||
"echo_test",
|
"echo_test",
|
||||||
"http://localhost:4545/cli/tests/echo_server.ts",
|
"http://localhost:4545/cli/tests/echo_server.ts",
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -338,7 +337,7 @@ mod tests {
|
||||||
)
|
)
|
||||||
.expect("Install failed");
|
.expect("Install failed");
|
||||||
|
|
||||||
let mut file_path = temp_dir.path().join(".deno/bin/echo_test");
|
let mut file_path = temp_dir.path().join("echo_test");
|
||||||
if cfg!(windows) {
|
if cfg!(windows) {
|
||||||
file_path = file_path.with_extension(".cmd");
|
file_path = file_path.with_extension(".cmd");
|
||||||
}
|
}
|
||||||
|
@ -347,7 +346,7 @@ mod tests {
|
||||||
// No force. Install failed.
|
// No force. Install failed.
|
||||||
let no_force_result = install(
|
let no_force_result = install(
|
||||||
DenoFlags::default(),
|
DenoFlags::default(),
|
||||||
None,
|
Some(temp_dir.path().to_path_buf()),
|
||||||
"echo_test",
|
"echo_test",
|
||||||
"http://localhost:4545/cli/tests/cat.ts", // using a different URL
|
"http://localhost:4545/cli/tests/cat.ts", // using a different URL
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -365,7 +364,7 @@ mod tests {
|
||||||
// Force. Install success.
|
// Force. Install success.
|
||||||
let force_result = install(
|
let force_result = install(
|
||||||
DenoFlags::default(),
|
DenoFlags::default(),
|
||||||
None,
|
Some(temp_dir.path().to_path_buf()),
|
||||||
"echo_test",
|
"echo_test",
|
||||||
"http://localhost:4545/cli/tests/cat.ts", // using a different URL
|
"http://localhost:4545/cli/tests/cat.ts", // using a different URL
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -375,12 +374,5 @@ mod tests {
|
||||||
// Assert modified
|
// Assert modified
|
||||||
let file_content_2 = fs::read_to_string(&file_path).unwrap();
|
let file_content_2 = fs::read_to_string(&file_path).unwrap();
|
||||||
assert!(file_content_2.contains("cat.ts"));
|
assert!(file_content_2.contains("cat.ts"));
|
||||||
|
|
||||||
if let Some(home) = original_home {
|
|
||||||
env::set_var("HOME", home);
|
|
||||||
}
|
|
||||||
if let Some(user_profile) = original_user_profile {
|
|
||||||
env::set_var("USERPROFILE", user_profile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue