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

cli: use npx for local mocha/ts-mocha #432

Merged
merged 4 commits into from
Jun 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ incremented for features.
* cli: Add `[scripts]` section to the Anchor.toml for specifying workspace scripts that can be run via `anchor run <script>` ([#400](https://github.com/project-serum/anchor/pull/400)).
* cli: `[clusters.<network>]` table entries can now also use `{ address = <base58-str>, idl = <filepath-str> }` to specify workspace programs ([#400](https://github.com/project-serum/anchor/pull/400)).

### Breaking Changes

* cli: Remove `--yarn` flag in favor of using `npx` ([#432](https://github.com/project-serum/anchor/pull/432)).

## [0.9.0] - 2021-06-15

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

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

1 change: 0 additions & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ dirs = "3.0"
heck = "0.3.1"
flate2 = "1.0.19"
rand = "0.7.3"
which = "4.1.0"
83 changes: 24 additions & 59 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ pub enum Command {
/// use this to save time when running test and the program code is not altered.
#[clap(long)]
skip_build: 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 @@ -258,14 +255,12 @@ fn main() -> Result<()> {
skip_deploy,
skip_local_validator,
skip_build,
yarn,
file,
} => test(
&opts.cfg_override,
skip_deploy,
skip_local_validator,
skip_build,
yarn,
file,
),
#[cfg(feature = "dev")]
Expand Down Expand Up @@ -978,7 +973,6 @@ fn test(
skip_deploy: bool,
skip_local_validator: bool,
skip_build: bool,
use_yarn: bool,
file: Option<String>,
) -> Result<()> {
with_workspace(cfg_override, |cfg, _path, _cargo| {
Expand Down Expand Up @@ -1012,64 +1006,35 @@ fn test(
// Setup log reader.
let log_streams = stream_logs(&cfg.provider.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();
let mut args = vec!["-t", "1000000"];
if let Some(ref file) = file {
args.push(file);
} else if ts_config_exist {
args.push("tests/**/*.spec.ts");
let cmd = if ts_config_exist { "ts-mocha" } else { "mocha" };
let mut args = if ts_config_exist {
vec![cmd, "-p", "./tsconfig.json"]
} else {
args.push("tests/");
}
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.provider.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.provider.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)
.env("ANCHOR_PROVIDER_URL", cfg.provider.cluster.url())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
.map_err(anyhow::Error::from)
.with_context(|| "ts-mocha"),
(false, false) => std::process::Command::new("mocha")
.args(args)
.env("ANCHOR_PROVIDER_URL", cfg.provider.cluster.url())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
.map_err(anyhow::Error::from)
.with_context(|| "mocha"),
vec![cmd]
};

exit
args.extend_from_slice(&[
"-t",
"1000000",
if let Some(ref file) = file {
file
} else if ts_config_exist {
"tests/**/*.spec.ts"
} else {
"tests/"
},
]);

std::process::Command::new("npx")
.args(args)
.env("ANCHOR_PROVIDER_URL", cfg.provider.cluster.url())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
.map_err(anyhow::Error::from)
.context(cmd)
};

// Check all errors and shut down.
Expand Down