Skip to content

Commit 30be7d3

Browse files
committed
try e2e
1 parent e3f9e99 commit 30be7d3

File tree

12 files changed

+63
-2
lines changed

12 files changed

+63
-2
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ members = [
1818
"crates/cli_yarn",
1919
"crates/dev-tools",
2020
"crates/snm_atom"
21-
]
21+
, "e2e"]
2222

2323
resolver = "2"
2424

e2e/Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "e2e"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
tempfile = "3.3"

e2e/src/main.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}

e2e/tests/node

5.39 MB
Binary file not shown.

e2e/tests/npm

5.41 MB
Binary file not shown.

e2e/tests/npx

5.41 MB
Binary file not shown.

e2e/tests/pnpm

5.41 MB
Binary file not shown.

e2e/tests/pnpx

5.41 MB
Binary file not shown.

e2e/tests/snm

5.29 MB
Binary file not shown.

e2e/tests/snm_install_test.rs

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use std::{
2+
env::{current_dir, var},
3+
error::Error,
4+
process::{Command, Output, Stdio},
5+
};
6+
7+
use tempfile::tempdir;
8+
9+
fn run_command(args: &[&str], envs: &Vec<(&str, String)>) -> Result<Output, Box<dyn Error>> {
10+
let output = Command::new("snm")
11+
.envs(envs.clone())
12+
.args(args)
13+
.stdout(Stdio::inherit())
14+
.stderr(Stdio::inherit())
15+
.stdin(Stdio::inherit())
16+
.output()?;
17+
Ok(output)
18+
}
19+
20+
#[test]
21+
fn test_parse_no_node_version_file() -> Result<(), Box<dyn Error>> {
22+
let dir = tempdir()?.path().to_path_buf();
23+
24+
let c = current_dir()?;
25+
26+
let original_path = var("PATH")?;
27+
28+
let new_path: String = format!("{}:{}", c.display().to_string(), original_path);
29+
30+
println!("临时目录路径: {} {}", dir.display(), c.display());
31+
32+
let envs = vec![
33+
("PATH", new_path),
34+
("SNM_HOME_DIR", dir.display().to_string()),
35+
];
36+
37+
let res = run_command(&["node", "install", "16.0.0"], &envs)?;
38+
39+
println!("res1--->: {:?}", res);
40+
41+
// 列出已安装的 Node.js 版本
42+
let res = run_command(&["node", "list"], &envs)?;
43+
44+
// let x = String::from_utf8(res.stdout)?;
45+
46+
println!("res2--->: {:?}", res);
47+
48+
// assert!(x.contains("16.0.0"));
49+
50+
Ok(())
51+
}

e2e/tests/yarn

5.41 MB
Binary file not shown.

justfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
build:
33
echo "Building the project..."
4-
cargo b
4+
cargo b --verbose --release
55

66
prerelease:
77
echo "Building the project for release..."

0 commit comments

Comments
 (0)