mirror of
https://github.com/denoland/deno.git
synced 2024-11-23 15:16:54 -05:00
1fb5858009
Co-authored-by: Erfan Safari <erfanshield@outlook.com>
78 lines
2.2 KiB
Rust
78 lines
2.2 KiB
Rust
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
|
|
|
use std::process::Command;
|
|
use tempfile::TempDir;
|
|
use test_util as util;
|
|
|
|
#[test]
|
|
fn installer_test_local_module_run() {
|
|
let temp_dir = TempDir::new().expect("tempdir fail");
|
|
let bin_dir = temp_dir.path().join("bin");
|
|
std::fs::create_dir(&bin_dir).unwrap();
|
|
let status = util::deno_cmd()
|
|
.current_dir(util::root_path())
|
|
.arg("install")
|
|
.arg("--name")
|
|
.arg("echo_test")
|
|
.arg("--root")
|
|
.arg(temp_dir.path())
|
|
.arg(util::testdata_path().join("echo.ts"))
|
|
.arg("hello")
|
|
.spawn()
|
|
.unwrap()
|
|
.wait()
|
|
.unwrap();
|
|
assert!(status.success());
|
|
let mut file_path = bin_dir.join("echo_test");
|
|
if cfg!(windows) {
|
|
file_path = file_path.with_extension("cmd");
|
|
}
|
|
assert!(file_path.exists());
|
|
// 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", util::target_dir())
|
|
.output()
|
|
.expect("failed to spawn script");
|
|
let stdout_str = std::str::from_utf8(&output.stdout).unwrap().trim();
|
|
assert!(stdout_str.ends_with("hello, foo"));
|
|
}
|
|
|
|
#[test]
|
|
fn installer_test_remote_module_run() {
|
|
let _g = util::http_server();
|
|
let temp_dir = TempDir::new().expect("tempdir fail");
|
|
let bin_dir = temp_dir.path().join("bin");
|
|
std::fs::create_dir(&bin_dir).unwrap();
|
|
let status = util::deno_cmd()
|
|
.current_dir(util::testdata_path())
|
|
.arg("install")
|
|
.arg("--name")
|
|
.arg("echo_test")
|
|
.arg("--root")
|
|
.arg(temp_dir.path())
|
|
.arg("http://localhost:4545/echo.ts")
|
|
.arg("hello")
|
|
.spawn()
|
|
.unwrap()
|
|
.wait()
|
|
.unwrap();
|
|
assert!(status.success());
|
|
let mut file_path = bin_dir.join("echo_test");
|
|
if cfg!(windows) {
|
|
file_path = file_path.with_extension("cmd");
|
|
}
|
|
assert!(file_path.exists());
|
|
let output = Command::new(file_path)
|
|
.current_dir(temp_dir.path())
|
|
.arg("foo")
|
|
.env("PATH", util::target_dir())
|
|
.output()
|
|
.expect("failed to spawn script");
|
|
assert!(std::str::from_utf8(&output.stdout)
|
|
.unwrap()
|
|
.trim()
|
|
.ends_with("hello, foo"));
|
|
}
|