Skip to content

Commit

Permalink
Add yarn flag to the anchor test command (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhly authored May 9, 2021
1 parent 06b40b7 commit 425997a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ incremented for features.

## [Unreleased]

## Features

* cli: Add yarn flag to test command ([#267](https://github.com/project-serum/anchor/pull/267)).

## [0.5.0] - 2021-05-07

## Features
Expand Down
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ dirs = "3.0"
heck = "0.3.1"
flate2 = "1.0.19"
rand = "0.7.3"
which = "4.1.0"
44 changes: 39 additions & 5 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ pub enum Command {
/// url is a localnet.
#[clap(long)]
skip_local_validator: bool,
/// Use this flag if you want to use yarn as your package manager.
#[clap(long)]
yarn: bool,
file: Option<String>,
},
/// Creates a new program.
Expand Down Expand Up @@ -230,8 +233,9 @@ fn main() -> Result<()> {
Command::Test {
skip_deploy,
skip_local_validator,
yarn,
file,
} => test(skip_deploy, skip_local_validator, file),
} => test(skip_deploy, skip_local_validator, yarn, file),
#[cfg(feature = "dev")]
Command::Airdrop { url } => airdrop(url),
Command::Cluster { subcmd } => cluster(subcmd),
Expand Down Expand Up @@ -909,7 +913,12 @@ enum OutFile {
}

// Builds, deploys, and tests all workspace programs in a single command.
fn test(skip_deploy: bool, skip_local_validator: bool, file: Option<String>) -> Result<()> {
fn test(
skip_deploy: bool,
skip_local_validator: bool,
use_yarn: bool,
file: Option<String>,
) -> Result<()> {
with_workspace(|cfg, _path, _cargo| {
// Bootup validator, if needed.
let validator_handle = match cfg.cluster.url() {
Expand All @@ -936,6 +945,11 @@ fn test(skip_deploy: bool, skip_local_validator: bool, file: Option<String>) ->
// Setup log reader.
let log_streams = stream_logs(&cfg.cluster.url());

// Check to see if yarn is installed, panic if not.
if use_yarn {
which::which("yarn").unwrap();
}

// Run the tests.
let test_result: Result<_> = {
let ts_config_exist = Path::new("tsconfig.json").exists();
Expand All @@ -947,8 +961,28 @@ fn test(skip_deploy: bool, skip_local_validator: bool, file: Option<String>) ->
} else {
args.push("tests/");
}
let exit = match ts_config_exist {
true => std::process::Command::new("ts-mocha")
let exit = match (ts_config_exist, use_yarn) {
(true, true) => std::process::Command::new("yarn")
.arg("ts-mocha")
.arg("-p")
.arg("./tsconfig.json")
.args(args)
.env("ANCHOR_PROVIDER_URL", cfg.cluster.url())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
.map_err(anyhow::Error::from)
.with_context(|| "ts-mocha"),
(false, true) => std::process::Command::new("yarn")
.arg("mocha")
.args(args)
.env("ANCHOR_PROVIDER_URL", cfg.cluster.url())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
.map_err(anyhow::Error::from)
.with_context(|| "mocha"),
(true, false) => std::process::Command::new("ts-mocha")
.arg("-p")
.arg("./tsconfig.json")
.args(args)
Expand All @@ -958,7 +992,7 @@ fn test(skip_deploy: bool, skip_local_validator: bool, file: Option<String>) ->
.output()
.map_err(anyhow::Error::from)
.with_context(|| "ts-mocha"),
false => std::process::Command::new("mocha")
(false, false) => std::process::Command::new("mocha")
.args(args)
.env("ANCHOR_PROVIDER_URL", cfg.cluster.url())
.stdout(Stdio::inherit())
Expand Down

0 comments on commit 425997a

Please sign in to comment.