From e1697421e2c00508cd78976b6ec586e056530c30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 31 Jan 2020 17:34:50 +0100 Subject: chore: remove std/installer, port installer tests to Rust (#3843) --- cli/tests/integration_tests.rs | 93 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) (limited to 'cli/tests/integration_tests.rs') diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index b8103fd76..fef69ad9e 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -69,6 +69,99 @@ fn fmt_test() { assert_eq!(expected, actual); } +#[test] +fn installer_test_local_module_run() { + use deno::flags::DenoFlags; + use deno::installer; + use std::env; + use std::path::PathBuf; + use std::process::Command; + use tempfile::TempDir; + + let temp_dir = TempDir::new().expect("tempdir fail"); + let local_module = env::current_dir().unwrap().join("tests/echo.ts"); + let local_module_str = local_module.to_string_lossy(); + installer::install( + DenoFlags::default(), + Some(temp_dir.path().to_string_lossy().to_string()), + "echo_test", + &local_module_str, + vec!["hello".to_string()], + ) + .expect("Failed to install"); + let mut file_path = temp_dir.path().join("echo_test"); + if cfg!(windows) { + file_path = file_path.with_extension(".cmd"); + } + assert!(file_path.exists()); + let path_var_name = if cfg!(windows) { "Path" } else { "PATH" }; + let paths_var = env::var_os(path_var_name).expect("PATH not set"); + let mut paths: Vec = env::split_paths(&paths_var).collect(); + paths.push(temp_dir.path().to_owned()); + paths.push(util::target_dir()); + let path_var_value = env::join_paths(paths).expect("Can't create PATH"); + // NOTE: using file_path here instead of exec_name, because tests + // shouldn't mess with user's PATH env variable + let output = Command::new(file_path) + .current_dir(temp_dir.path()) + .arg("foo") + .env(path_var_name, path_var_value) + .output() + .expect("failed to spawn script"); + + assert_eq!( + std::str::from_utf8(&output.stdout).unwrap().trim(), + "hello, foo" + ); + drop(temp_dir); +} + +#[test] +fn installer_test_remote_module_run() { + use deno::flags::DenoFlags; + use deno::installer; + use std::env; + use std::path::PathBuf; + use std::process::Command; + use tempfile::TempDir; + + let g = util::http_server(); + let temp_dir = TempDir::new().expect("tempdir fail"); + installer::install( + DenoFlags::default(), + Some(temp_dir.path().to_string_lossy().to_string()), + "echo_test", + "http://localhost:4545/tests/echo.ts", + vec!["hello".to_string()], + ) + .expect("Failed to install"); + let mut file_path = temp_dir.path().join("echo_test"); + if cfg!(windows) { + file_path = file_path.with_extension(".cmd"); + } + assert!(file_path.exists()); + let path_var_name = if cfg!(windows) { "Path" } else { "PATH" }; + let paths_var = env::var_os(path_var_name).expect("PATH not set"); + let mut paths: Vec = env::split_paths(&paths_var).collect(); + paths.push(temp_dir.path().to_owned()); + paths.push(util::target_dir()); + let path_var_value = env::join_paths(paths).expect("Can't create PATH"); + // NOTE: using file_path here instead of exec_name, because tests + // shouldn't mess with user's PATH env variable + let output = Command::new(file_path) + .current_dir(temp_dir.path()) + .arg("foo") + .env(path_var_name, path_var_value) + .output() + .expect("failed to spawn script"); + assert_eq!( + std::str::from_utf8(&output.stdout).unwrap().trim(), + "hello, foo" + ); + drop(temp_dir); + drop(g) +} + #[test] fn js_unit_tests() { let g = util::http_server(); -- cgit v1.2.3