Skip to content

Commit

Permalink
feat(cli/test): add DENO_JOBS env variable for test subcommand (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkldshv authored Jul 15, 2022
1 parent f9b692e commit ee0c058
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cli/args/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,10 @@ static ENV_VARIABLES_HELP: &str = r#"ENVIRONMENT VARIABLES:
DENO_NO_PROMPT Set to disable permission prompts on access
(alternative to passing --no-prompt on invocation)
DENO_WEBGPU_TRACE Directory to use for wgpu traces
DENO_JOBS Number of parallel workers used for test subcommand.
Defaults to number of available CPUs when used with
--jobs flag and no value is provided.
Defaults to 1 when --jobs flag is not used.
HTTP_PROXY Proxy address for HTTP requests
(module downloads, fetch)
HTTPS_PROXY Proxy address for HTTPS requests
Expand Down Expand Up @@ -1548,7 +1552,7 @@ fn test_subcommand<'a>() -> Command<'a> {
Arg::new("jobs")
.short('j')
.long("jobs")
.help("Number of parallel workers, defaults to # of CPUs when no value is provided. Defaults to 1 when the option is not present.")
.help("Number of parallel workers, defaults to number of available CPUs when no value is provided. Defaults to 1 when the option is not present.")
.min_values(0)
.max_values(1)
.takes_value(true)
Expand Down Expand Up @@ -2666,6 +2670,10 @@ fn test_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
let concurrent_jobs = if matches.is_present("jobs") {
if let Some(value) = matches.value_of("jobs") {
value.parse().unwrap()
} else if let Ok(value) = env::var("DENO_JOBS") {
value
.parse::<NonZeroUsize>()
.unwrap_or(NonZeroUsize::new(1).unwrap())
} else {
std::thread::available_parallelism()
.unwrap_or(NonZeroUsize::new(1).unwrap())
Expand Down
26 changes: 26 additions & 0 deletions cli/tests/integration/test_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,32 @@ itest!(collect {
output: "test/collect.out",
});

itest!(jobs_flag {
args: "test test/short-pass.ts --jobs",
exit_code: 0,
output: "test/short-pass.out",
});

itest!(jobs_flag_with_numeric_value {
args: "test test/short-pass.ts --jobs=2",
exit_code: 0,
output: "test/short-pass-jobs-flag-with-numeric-value.out",
});

itest!(jobs_flag_with_env_variable {
args: "test test/short-pass.ts --jobs",
envs: vec![("DENO_JOBS".to_owned(), "2".to_owned())],
exit_code: 0,
output: "test/short-pass.out",
});

itest!(jobs_flag_with_numeric_value_and_env_var {
args: "test test/short-pass.ts --jobs=2",
envs: vec![("DENO_JOBS".to_owned(), "3".to_owned())],
exit_code: 0,
output: "test/short-pass-jobs-flag-with-numeric-value.out",
});

itest!(load_unload {
args: "test test/load_unload.ts",
exit_code: 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Check [WILDCARD]/test/short-pass.ts
running 1 test from ./test/short-pass.ts
test ... ok ([WILDCARD])

ok | 1 passed | 0 failed ([WILDCARD])

6 changes: 6 additions & 0 deletions cli/tests/testdata/test/short-pass.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Check [WILDCARD]/test/short-pass.ts
running 1 test from ./test/short-pass.ts
test ... ok ([WILDCARD])

ok | 1 passed | 0 failed ([WILDCARD])

1 change: 1 addition & 0 deletions cli/tests/testdata/test/short-pass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deno.test("test", () => {});

0 comments on commit ee0c058

Please sign in to comment.