diff --git a/Cargo.toml b/Cargo.toml index 0a8c9d90..5104f443 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ members = [ "crates/cli_yarn", "crates/dev-tools", "crates/snm_atom" -] +, "e2e"] resolver = "2" diff --git a/e2e/Cargo.toml b/e2e/Cargo.toml new file mode 100644 index 00000000..fa5e62b3 --- /dev/null +++ b/e2e/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "e2e" +version = "0.1.0" +edition = "2021" + +[dependencies] +tempfile = "3.3" \ No newline at end of file diff --git a/e2e/src/main.rs b/e2e/src/main.rs new file mode 100644 index 00000000..e7a11a96 --- /dev/null +++ b/e2e/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/e2e/tests/node b/e2e/tests/node new file mode 100755 index 00000000..083640eb Binary files /dev/null and b/e2e/tests/node differ diff --git a/e2e/tests/npm b/e2e/tests/npm new file mode 100755 index 00000000..8081b16a Binary files /dev/null and b/e2e/tests/npm differ diff --git a/e2e/tests/npx b/e2e/tests/npx new file mode 100755 index 00000000..2d8e40ea Binary files /dev/null and b/e2e/tests/npx differ diff --git a/e2e/tests/pnpm b/e2e/tests/pnpm new file mode 100755 index 00000000..ffda45b4 Binary files /dev/null and b/e2e/tests/pnpm differ diff --git a/e2e/tests/pnpx b/e2e/tests/pnpx new file mode 100755 index 00000000..6187b528 Binary files /dev/null and b/e2e/tests/pnpx differ diff --git a/e2e/tests/snm b/e2e/tests/snm new file mode 100755 index 00000000..dd2094ee Binary files /dev/null and b/e2e/tests/snm differ diff --git a/e2e/tests/snm_install_test.rs b/e2e/tests/snm_install_test.rs new file mode 100644 index 00000000..20c858f0 --- /dev/null +++ b/e2e/tests/snm_install_test.rs @@ -0,0 +1,51 @@ +use std::{ + env::{current_dir, var}, + error::Error, + process::{Command, Output, Stdio}, +}; + +use tempfile::tempdir; + +fn run_command(args: &[&str], envs: &Vec<(&str, String)>) -> Result> { + let output = Command::new("snm") + .envs(envs.clone()) + .args(args) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .stdin(Stdio::inherit()) + .output()?; + Ok(output) +} + +#[test] +fn test_parse_no_node_version_file() -> Result<(), Box> { + let dir = tempdir()?.path().to_path_buf(); + + let c = current_dir()?; + + let original_path = var("PATH")?; + + let new_path: String = format!("{}:{}", c.display().to_string(), original_path); + + println!("临时目录路径: {} {}", dir.display(), c.display()); + + let envs = vec![ + ("PATH", new_path), + ("SNM_HOME_DIR", dir.display().to_string()), + ]; + + let res = run_command(&["node", "install", "16.0.0"], &envs)?; + + println!("res1--->: {:?}", res); + + // 列出已安装的 Node.js 版本 + let res = run_command(&["node", "list"], &envs)?; + + // let x = String::from_utf8(res.stdout)?; + + println!("res2--->: {:?}", res); + + // assert!(x.contains("16.0.0")); + + Ok(()) +} diff --git a/e2e/tests/yarn b/e2e/tests/yarn new file mode 100755 index 00000000..d5aa288b Binary files /dev/null and b/e2e/tests/yarn differ diff --git a/justfile b/justfile index 18242516..094d174f 100644 --- a/justfile +++ b/justfile @@ -1,7 +1,7 @@ build: echo "Building the project..." - cargo b + cargo b --verbose --release prerelease: echo "Building the project for release..."