Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add yarn flag to the anchor test command #267

Merged
merged 2 commits into from
May 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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