Skip to content

Commit

Permalink
Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Sep 27, 2023
1 parent 629eee8 commit 55c6db2
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#### 🚀 Updates

- Added a `proto pin` command, which is a merge of the old `proto global` and `proto local` commands.
- Added a `pin-latest` setting to `~/.proto/config.toml` that'll automatically pin tools when they're being installed with the "latest" version.
- Updated `proto install` to auto-clean stale plugins after a successful installation.

## 0.18.4
Expand Down
82 changes: 81 additions & 1 deletion crates/cli/tests/install_uninstall_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod utils;

use proto_core::{ToolManifest, UnresolvedVersionSpec, VersionSpec};
use proto_core::{ToolManifest, ToolsConfig, UnresolvedVersionSpec, VersionSpec};
use starbase_sandbox::predicates::prelude::*;
use std::collections::HashSet;
use utils::*;
Expand Down Expand Up @@ -231,4 +231,84 @@ mod install_uninstall {
Some(UnresolvedVersionSpec::parse("19.0.0").unwrap())
);
}

#[test]
fn can_pin_latest_locally_using_setting() {
let temp = create_empty_sandbox();
temp.create_file("config.toml", "pin-latest = \"local\"");

let manifest_file = temp.path().join("tools/node/manifest.json");

// We set a default version here to compare against later
let mut manifest = ToolManifest::load(&manifest_file).unwrap();
manifest.default_version = Some(UnresolvedVersionSpec::parse("18.0.0").unwrap());
manifest.save().unwrap();

let mut cmd = create_proto_command(temp.path());
cmd.arg("install")
.arg("node")
.arg("--")
.arg("--no-bundled-npm")
.assert();

let manifest = ToolManifest::load(&manifest_file).unwrap();

assert_eq!(
manifest.default_version.unwrap(),
UnresolvedVersionSpec::parse("18.0.0").unwrap()
);

let tools = ToolsConfig::load_from(temp.path()).unwrap();

assert!(tools.tools.get("node").is_some());
}

#[test]
fn can_pin_latest_globally_using_setting() {
let temp = create_empty_sandbox();
temp.create_file("config.toml", "pin-latest = \"global\"");

let manifest_file = temp.path().join("tools/node/manifest.json");

// We set a default version here to compare against later
let mut manifest = ToolManifest::load(&manifest_file).unwrap();
manifest.default_version = Some(UnresolvedVersionSpec::parse("18.0.0").unwrap());
manifest.save().unwrap();

let mut cmd = create_proto_command(temp.path());
cmd.arg("install")
.arg("node")
.arg("--")
.arg("--no-bundled-npm")
.assert();

let manifest = ToolManifest::load(&manifest_file).unwrap();

assert_ne!(
manifest.default_version.unwrap(),
UnresolvedVersionSpec::parse("18.0.0").unwrap()
);

let tools = ToolsConfig::load_from(temp.path()).unwrap();

assert!(tools.tools.get("node").is_none());
}

#[test]
fn doesnt_pin_using_setting_if_not_latest() {
let temp = create_empty_sandbox();
temp.create_file("config.toml", "pin-latest = \"local\"");

let mut cmd = create_proto_command(temp.path());
cmd.arg("install")
.arg("node")
.arg("20.0.0")
.arg("--")
.arg("--no-bundled-npm")
.assert();

let tools = ToolsConfig::load_from(temp.path()).unwrap();

assert!(tools.tools.get("node").is_none());
}
}

0 comments on commit 55c6db2

Please sign in to comment.