Skip to content

Commit bff8d05

Browse files
committed
chore: add test
1 parent ac2c01c commit bff8d05

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

crates/cli/tests/install.rs

+31-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use assert_cmd::prelude::*;
55
use command_extra::CommandExtra;
66
use pacquet_testing_utils::{
77
bin::{AddDefaultNpmrcInfo, CommandTempCwd},
8-
fs::{get_all_files, get_all_folders, is_symlink_or_junction},
8+
fs::{get_all_files, get_all_folders, is_symlink_or_junction}, panic_after,
99
};
1010
use pipe_trait::Pipe;
11-
use std::fs;
11+
use std::{fs, thread, time::Duration};
1212

1313
#[test]
1414
fn should_install_dependencies() {
@@ -140,3 +140,32 @@ fn should_install_index_files() {
140140

141141
drop(root); // cleanup
142142
}
143+
144+
#[test]
145+
fn should_install_duplicated_dependencies() {
146+
let CommandTempCwd { pacquet, root, workspace, .. } =
147+
CommandTempCwd::init().add_default_npmrc();
148+
149+
eprintln!("Creating package.json...");
150+
let manifest_path = workspace.join("package.json");
151+
let package_json_content = serde_json::json!({
152+
"dependencies": {
153+
"express": "4.18.2",
154+
},
155+
"devDependencies": {
156+
"express": "4.18.2",
157+
},
158+
});
159+
fs::write(manifest_path, package_json_content.to_string()).expect("write to package.json");
160+
161+
panic_after(Duration::from_secs(30), move || {
162+
thread::sleep(Duration::from_millis(200));
163+
eprintln!("Executing command...");
164+
pacquet.with_arg("install").assert().success();
165+
eprintln!("Make sure the package is installed");
166+
assert!(is_symlink_or_junction(&workspace.join("node_modules/express")).unwrap());
167+
assert!(workspace.join("node_modules/.pnpm/[email protected]").exists());
168+
});
169+
170+
drop(root); // cleanup
171+
}

crates/testing-utils/src/lib.rs

+20
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,22 @@
1+
use std::{ thread, sync::mpsc, time::Duration};
12
pub mod bin;
23
pub mod fs;
4+
5+
pub fn panic_after<T, F>(d: Duration, f: F) -> T
6+
where
7+
T: Send + 'static,
8+
F: FnOnce() -> T,
9+
F: Send + 'static,
10+
{
11+
let (done_tx, done_rx) = mpsc::channel();
12+
let handle = thread::spawn(move || {
13+
let val = f();
14+
done_tx.send(()).expect("Unable to send completion signal");
15+
val
16+
});
17+
18+
match done_rx.recv_timeout(d) {
19+
Ok(_) => handle.join().expect("test panicked"),
20+
Err(_) => panic!("test timeout"),
21+
}
22+
}

0 commit comments

Comments
 (0)