summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Ladyshau <47859603+mrkldshv@users.noreply.github.com>2022-07-15 16:29:55 +0200
committerGitHub <noreply@github.com>2022-07-15 10:29:55 -0400
commitee0c0586b318fe23908a3b9b4311b26d79c5c8a1 (patch)
tree7e584fdb24e1637a8a55d47a358970888658ab87
parentf9b692e68e97ab6d39ad03988e973279a32cceca (diff)
feat(cli/test): add `DENO_JOBS` env variable for `test` subcommand (#14929)
-rw-r--r--cli/args/flags.rs10
-rw-r--r--cli/tests/integration/test_tests.rs26
-rw-r--r--cli/tests/testdata/test/short-pass-jobs-flag-with-numeric-value.out6
-rw-r--r--cli/tests/testdata/test/short-pass.out6
-rw-r--r--cli/tests/testdata/test/short-pass.ts1
5 files changed, 48 insertions, 1 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs
index 8b8cf8d86..c6fbb320b 100644
--- a/cli/args/flags.rs
+++ b/cli/args/flags.rs
@@ -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
@@ -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)
@@ -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())
diff --git a/cli/tests/integration/test_tests.rs b/cli/tests/integration/test_tests.rs
index 981923359..e1c7700db 100644
--- a/cli/tests/integration/test_tests.rs
+++ b/cli/tests/integration/test_tests.rs
@@ -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,
diff --git a/cli/tests/testdata/test/short-pass-jobs-flag-with-numeric-value.out b/cli/tests/testdata/test/short-pass-jobs-flag-with-numeric-value.out
new file mode 100644
index 000000000..09b72d5fd
--- /dev/null
+++ b/cli/tests/testdata/test/short-pass-jobs-flag-with-numeric-value.out
@@ -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])
+
diff --git a/cli/tests/testdata/test/short-pass.out b/cli/tests/testdata/test/short-pass.out
new file mode 100644
index 000000000..09b72d5fd
--- /dev/null
+++ b/cli/tests/testdata/test/short-pass.out
@@ -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])
+
diff --git a/cli/tests/testdata/test/short-pass.ts b/cli/tests/testdata/test/short-pass.ts
new file mode 100644
index 000000000..03818ae8d
--- /dev/null
+++ b/cli/tests/testdata/test/short-pass.ts
@@ -0,0 +1 @@
+Deno.test("test", () => {});