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

feat: add deno test subcommand #2783

Merged
merged 1 commit into from
Aug 15, 2019
Merged
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
74 changes: 74 additions & 0 deletions cli/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,40 @@ Automatically downloads Prettier dependencies on first run.
.multiple(true)
.required(true),
),
).subcommand(
add_run_args(SubCommand::with_name("test"))
.about("Run tests")
.long_about(
"Run tests using test runner

Automatically downloads test runner on first run.

deno test **/*_test.ts **/test.ts",
).arg(
Arg::with_name("failfast")
.short("f")
.long("failfast")
.help("Stop on first error")
.takes_value(false),
).arg(
Arg::with_name("quiet")
.short("q")
.long("quiet")
.help("Don't show output from test cases")
.takes_value(false)
).arg(
Arg::with_name("exclude")
.short("e")
.long("exclude")
.help("List of file names to exclude from run")
.takes_value(true)
.multiple(true)
).arg(
Arg::with_name("files")
.help("List of file names to run")
.takes_value(true)
.multiple(true)
),
).subcommand(
add_run_args(SubCommand::with_name("run"))
.settings(&[
Expand Down Expand Up @@ -521,6 +555,10 @@ pub fn parse_flags(
if let Some(run_matches) = matches.subcommand_matches("run") {
flags = parse_run_args(flags.clone(), run_matches);
}
// flags specific to "test" subcommand
if let Some(test_matches) = matches.subcommand_matches("test") {
flags = parse_run_args(flags.clone(), test_matches);
}

flags
}
Expand Down Expand Up @@ -643,6 +681,8 @@ fn parse_script_args(
const PRETTIER_URL: &str = "https://deno.land/std@v0.11/prettier/main.ts";
/// Used for `deno install...` subcommand
const INSTALLER_URL: &str = "https://deno.land/std@v0.11/installer/mod.ts";
/// Used for `deno test...` subcommand
const TEST_RUNNER_URL: &str = "https://deno.land/std@c44e536/testing/runner.ts";

/// These are currently handled subcommands.
/// There is no "Help" subcommand because it's handled by `clap::App` itself.
Expand Down Expand Up @@ -795,6 +835,40 @@ pub fn flags_from_vec(
_ => unreachable!(),
}
}
("test", Some(test_match)) => {
flags.allow_read = true;
argv.push(TEST_RUNNER_URL.to_string());

if test_match.is_present("quiet") {
argv.push("--quiet".to_string());
}

if test_match.is_present("failfast") {
argv.push("--failfast".to_string());
}

if test_match.is_present("exclude") {
argv.push("--exclude".to_string());
let exclude: Vec<String> = test_match
.values_of("exclude")
.unwrap()
.map(String::from)
.collect();
argv.extend(exclude);
}

if test_match.is_present("files") {
argv.push("--".to_string());
let files: Vec<String> = test_match
.values_of("files")
.unwrap()
.map(String::from)
.collect();
argv.extend(files);
}

DenoSubcommand::Run
}
("types", Some(_)) => DenoSubcommand::Types,
("run", Some(run_match)) => {
match run_match.subcommand() {
Expand Down