Skip to content

Commit

Permalink
test(cli/install): use registry-mock
Browse files Browse the repository at this point in the history
  • Loading branch information
KSXGitHub committed Nov 15, 2023
1 parent 485db26 commit 433a344
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 306 deletions.
49 changes: 20 additions & 29 deletions crates/cli/tests/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub use _utils::*;
use assert_cmd::prelude::*;
use command_extra::CommandExtra;
use pacquet_testing_utils::{
bin::{AddDefaultNpmrcInfo, CommandTempCwd},
bin::{AddMockedRegistry, CommandTempCwd},
fs::{get_all_files, get_all_folders, is_symlink_or_junction},
};
use pipe_trait::Pipe;
Expand All @@ -13,17 +13,14 @@ use std::fs;
#[test]
fn should_install_dependencies() {
let CommandTempCwd { pacquet, root, workspace, npmrc_info, .. } =
CommandTempCwd::init().add_default_npmrc();
let AddDefaultNpmrcInfo { store_dir, .. } = npmrc_info;
CommandTempCwd::init().add_mocked_registry();
let AddMockedRegistry { store_dir, mock_instance, .. } = npmrc_info;

eprintln!("Creating package.json...");
let manifest_path = workspace.join("package.json");
let package_json_content = serde_json::json!({
"dependencies": {
"is-odd": "3.0.1",
},
"devDependencies": {
"fast-decode-uri-component": "1.0.1",
"@pnpm.e2e/hello-world-js-bin-parent": "1.0.0",
},
});
fs::write(&manifest_path, package_json_content.to_string()).expect("write to package.json");
Expand All @@ -32,38 +29,35 @@ fn should_install_dependencies() {
pacquet.with_arg("install").assert().success();

eprintln!("Make sure the package is installed");
assert!(is_symlink_or_junction(&workspace.join("node_modules/is-odd")).unwrap());
assert!(workspace.join("node_modules/.pnpm/is-odd@3.0.1").exists());
let symlink_path = workspace.join("node_modules/@pnpm.e2e/hello-world-js-bin-parent");
assert!(is_symlink_or_junction(&symlink_path).unwrap());
let virtual_path =
workspace.join("node_modules/.pnpm/@pnpm.e2e+hello-world-js-bin-parent@1.0.0");
assert!(virtual_path.exists());

eprintln!("Make sure it installs direct dependencies");
assert!(!workspace.join("node_modules/is-number").exists());
assert!(workspace.join("node_modules/.pnpm/is-number@6.0.0").exists());

eprintln!("Make sure we install dev-dependencies as well");
assert!(
is_symlink_or_junction(&workspace.join("node_modules/fast-decode-uri-component")).unwrap()
);
assert!(workspace.join("node_modules/.pnpm/fast-decode-uri-component@1.0.1").is_dir());
assert!(!workspace.join("node_modules/@pnpm.e2e/hello-world-js-bin").exists());
assert!(workspace.join("node_modules/.pnpm/@pnpm.e2e+hello-world-js-bin@1.0.0").exists());

eprintln!("Snapshot");
let workspace_folders = get_all_folders(&workspace);
let store_files = get_all_files(&store_dir);
insta::assert_debug_snapshot!((workspace_folders, store_files));

drop(root); // cleanup
drop((root, mock_instance)); // cleanup
}

#[test]
fn should_install_exec_files() {
let CommandTempCwd { pacquet, root, workspace, npmrc_info, .. } =
CommandTempCwd::init().add_default_npmrc();
let AddDefaultNpmrcInfo { store_dir, .. } = npmrc_info;
CommandTempCwd::init().add_mocked_registry();
let AddMockedRegistry { store_dir, mock_instance, .. } = npmrc_info;

eprintln!("Creating package.json...");
let manifest_path = workspace.join("package.json");
let package_json_content = serde_json::json!({
"dependencies": {
"pretty-exec": "0.3.10",
"@pnpm.e2e/hello-world-js-bin-parent": "1.0.0",
},
});
fs::write(&manifest_path, package_json_content.to_string()).expect("write to package.json");
Expand Down Expand Up @@ -110,23 +104,20 @@ fn should_install_exec_files() {
eprintln!("Snapshot");
insta::assert_debug_snapshot!(store_files);

drop(root); // cleanup
drop((root, mock_instance)); // cleanup
}

#[test]
fn should_install_index_files() {
let CommandTempCwd { pacquet, root, workspace, npmrc_info, .. } =
CommandTempCwd::init().add_default_npmrc();
let AddDefaultNpmrcInfo { store_dir, .. } = npmrc_info;
CommandTempCwd::init().add_mocked_registry();
let AddMockedRegistry { store_dir, mock_instance, .. } = npmrc_info;

eprintln!("Creating package.json...");
let manifest_path = workspace.join("package.json");
let package_json_content = serde_json::json!({
"dependencies": {
"is-odd": "3.0.1",
},
"devDependencies": {
"fast-decode-uri-component": "1.0.1",
"@pnpm.e2e/hello-world-js-bin-parent": "1.0.0",
},
});
fs::write(&manifest_path, package_json_content.to_string()).expect("write to package.json");
Expand All @@ -138,5 +129,5 @@ fn should_install_index_files() {
let index_file_contents = index_file_contents(&store_dir);
insta::assert_yaml_snapshot!(index_file_contents);

drop(root); // cleanup
drop((root, mock_instance)); // cleanup
}
Original file line number Diff line number Diff line change
@@ -1,40 +1,30 @@
---
source: crates/cli/tests/install.rs
assertion_line: 51
assertion_line: 45
expression: "(workspace_folders, store_files)"
---
(
[
"node_modules",
"node_modules/.pnpm",
"node_modules/.pnpm/fast-decode-uri-component@1.0.1",
"node_modules/.pnpm/fast-decode-uri-component@1.0.1/node_modules",
"node_modules/.pnpm/fast-decode-uri-component@1.0.1/node_modules/fast-decode-uri-component",
"node_modules/.pnpm/is-number@6.0.0",
"node_modules/.pnpm/is-number@6.0.0/node_modules",
"node_modules/.pnpm/is-number@6.0.0/node_modules/is-number",
"node_modules/.pnpm/is-odd@3.0.1",
"node_modules/.pnpm/is-odd@3.0.1/node_modules",
"node_modules/.pnpm/is-odd@3.0.1/node_modules/is-number",
"node_modules/.pnpm/is-odd@3.0.1/node_modules/is-odd",
"node_modules/fast-decode-uri-component",
"node_modules/is-odd",
"node_modules/.pnpm/@pnpm.e2e+hello-world-js-bin-parent@1.0.0",
"node_modules/.pnpm/@pnpm.e2e+hello-world-js-bin-parent@1.0.0/node_modules",
"node_modules/.pnpm/@pnpm.e2e+hello-world-js-bin-parent@1.0.0/node_modules/@pnpm.e2e",
"node_modules/.pnpm/@pnpm.e2e+hello-world-js-bin-parent@1.0.0/node_modules/@pnpm.e2e/hello-world-js-bin",
"node_modules/.pnpm/@pnpm.e2e+hello-world-js-bin-parent@1.0.0/node_modules/@pnpm.e2e/hello-world-js-bin-parent",
"node_modules/.pnpm/@pnpm.e2e+hello-world-js-bin@1.0.0",
"node_modules/.pnpm/@pnpm.e2e+hello-world-js-bin@1.0.0/node_modules",
"node_modules/.pnpm/@pnpm.e2e+hello-world-js-bin@1.0.0/node_modules/@pnpm.e2e",
"node_modules/.pnpm/@pnpm.e2e+hello-world-js-bin@1.0.0/node_modules/@pnpm.e2e/hello-world-js-bin",
"node_modules/@pnpm.e2e",
"node_modules/@pnpm.e2e/hello-world-js-bin-parent",
],
[
"v3/files/01/d306b80f4b1678c655f3b0685db1f7a741fc746d251c00e925298ab89630a3167bde8c7d8d779b72770c41f9f302bb1e3f312672ce7aa8e6c156c319eeeada",
"v3/files/17/54b7271ca0e30dc7d775986711a2b61b298200c12f867bde6f7e19d56047c9ab77a93304520fa1a31b0c3a4e6fb6b310f89dd8cb4d95a5c662807ef733f85f",
"v3/files/1a/5c01a1321e71a1c263fb83878cbba2686f71f571b42c2d40d93858bf1f4c6ff7f625125a68932c243e75ead4a9d2f18d9b22b3fe55c39fe6605a42b2e70620",
"v3/files/37/8eb16c230fce354ef7e72722ee708cbefea9a481aa597b06fefc12f665ab60176cbf04d6bc159be42ccdbc51764d71516f86bb28a01b0e60c76a2753f1cf44",
"v3/files/40/fe18b2c1f241075b732727110323f3e29f9d6c8765ff0222bccfa34784caa8abcd18ffbd4bbfab979e5478ace273a74ed3a0a22f0261334fa7c59e032edbde",
"v3/files/54/7bcd683e2f9f7b0c2790c637b9231539947be923479534592d91886a56d6262fdc1d8ced24ac2cc3adfda139fe399dc7502d382c7afc536e3057a7cf11e6c0",
"v3/files/55/dcbc7fff1ac1c4755f4cbf24ba21e0dcae062c802d3db937d2b6182f4554dd85d14529a0c9688eac825a345b63ab8b2e5d7699e2be07178df5bb8a072235eb",
"v3/files/58/01e592e94aa4076c179180956f33f8262fa7157a06bfe636a6854bd3b9b2ddf44780ffa1405642ad8ece2ed6514e19a28178cbecdcf5608a3be710bbf3c0d4",
"v3/files/60/ab54849d6cfd7b05076c3bc4d9baffe1f800f4d5e2d67c39c521a7a3d93b347ce5a8e45397102e40e2103652c543c8e7bb161c15d0a6e34ec1a9d11c168d2a",
"v3/files/88/1f101d2f1886fc5f9ac5c8d25e5540908e140031169ea41a4a9941cf95fe2711c1292c1995609c6f174b3815cc0dcc6cd2a10339a348d39fe75bc77b53ba9e",
"v3/files/9f/cbe5dc86bc33bdb4f125559e767c3aaad94c7c4b21b80b694d9b0158ee0f10ee53b127c2bf05db9768afdaf1fb6778fd08a19412fb3c1adad655863e6c351d",
"v3/files/ca/65df16eb450ab63f90f107a8cc9ac82da9635408e813a6f6d3e13cfba78917b31b66652479ebba54b612566600b2ab1bc16b82d082c5f87803961a8e9e3931",
"v3/files/e5/c2514d2b0d3d6bedad24fdd75c55e780211cf0692c21f401201c2d7dfa990ad00188bd68b30c826aaa2a72ecad12a74bc03430384f933b1751035dd1b18ca2",
"v3/files/f7/02180f4465a777127ad6a211306dd564993c17f7d3d9401604df4bc657d8d888902de632a4cf55b551ddfb9f84ba8a900788773f03c77836143ef94e182c7c",
"v3/files/ff/d3f3fed65d7b489216916772c6180b5c1714ddde16e7e2c99ff5f8a4214bb8f884a0c1d06a1b1a8a4b0d6252ad85b533b1626f0dd8d474f2283f6cdfd69f6c",
"v3/files/02/f9d952341eade675d0a8f5da14d4277fded62f937242292c2cf5f1bb0eda101b5f803098d64e2a138f4bfe4cdf326cfaf8f6b4015476ab86d25df03ddec731-exec",
"v3/files/68/b837b4fd7982b081521e51b14a167ccdb272b3c499202449d07d48d78a2fa7bb8652d3a894bb06ac6e3995e5126ee3470f73b5775584940751fce8be468405",
"v3/files/93/e31fcd9144a604f87d04fa8fb4a058202c579df17fd2b21301e17ac0ae4f3e2bae90ced7ae71b71218bd4a789e355ef7b8bd8899cdb785250071b229503b2e",
"v3/files/a5/541962367c9c3aaaa8be96312f7efedf7ae638bd051e80573649ca93b4852f4f2749efdce9f19fa7355b3a6d9130eded64e4b3c0efe753622735c5069482cd-index.json",
"v3/files/bf/0c878f2a4f2ec6f231bb2d414547efb15eb22a673815cba36acfd89633cd4c8affcbdc9378e90ad4d8fc654de921d1f67444be94e6a2f81bda9330be60be93-exec",
"v3/files/dd/feae8107ea156f46477e8e49e4dfb12365ba9ee122c953db785a5f776f4ff7b91b25378889dab77fb4188f8caaf45cc1c373b01ad326aef20d6a77c24ecefd-index.json",
],
)
Loading

0 comments on commit 433a344

Please sign in to comment.