Skip to content

Commit df0d817

Browse files
committed
feat: add DENO_JOBS env variable and deprecate numeric value for --jobs
1 parent 7e06d33 commit df0d817

File tree

6 files changed

+78
-1
lines changed

6 files changed

+78
-1
lines changed

cli/args/flags.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,10 @@ static ENV_VARIABLES_HELP: &str = r#"ENVIRONMENT VARIABLES:
480480
DENO_NO_PROMPT Set to disable permission prompts on access
481481
(alternative to passing --no-prompt on invocation)
482482
DENO_WEBGPU_TRACE Directory to use for wgpu traces
483+
DENO_JOBS Number of parallel workers used for test subcommand.
484+
Defaults to number of available CPUs when used with
485+
--jobs flag and no value is provided.
486+
Defaults to 1 when --jobs flag is not used.
483487
HTTP_PROXY Proxy address for HTTP requests
484488
(module downloads, fetch)
485489
HTTPS_PROXY Proxy address for HTTPS requests
@@ -1548,9 +1552,10 @@ fn test_subcommand<'a>() -> Command<'a> {
15481552
Arg::new("jobs")
15491553
.short('j')
15501554
.long("jobs")
1551-
.help("Number of parallel workers, defaults to # of CPUs when no value is provided. Defaults to 1 when the option is not present.")
1555+
.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.")
15521556
.min_values(0)
15531557
.max_values(1)
1558+
.require_equals(true)
15541559
.takes_value(true)
15551560
.validator(|val: &str| match val.parse::<NonZeroUsize>() {
15561561
Ok(_) => Ok(()),
@@ -2665,7 +2670,15 @@ fn test_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
26652670

26662671
let concurrent_jobs = if matches.is_present("jobs") {
26672672
if let Some(value) = matches.value_of("jobs") {
2673+
println!(
2674+
"{}",
2675+
crate::colors::yellow("Warning: --jobs flag with numeric value is deprecated. Use 'DENO_JOBS' environment variable with --jobs flag instead."),
2676+
);
26682677
value.parse().unwrap()
2678+
} else if let Ok(value) = env::var("DENO_JOBS") {
2679+
value
2680+
.parse::<NonZeroUsize>()
2681+
.unwrap_or(NonZeroUsize::new(1).unwrap())
26692682
} else {
26702683
std::thread::available_parallelism()
26712684
.unwrap_or(NonZeroUsize::new(1).unwrap())

cli/tests/integration/test_tests.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,32 @@ itest!(collect {
6262
output: "test/collect.out",
6363
});
6464

65+
itest!(jobs_flag {
66+
args: "test test/short-pass.ts --jobs",
67+
exit_code: 0,
68+
output: "test/short-pass.out",
69+
});
70+
71+
itest!(jobs_flag_with_numeric_value {
72+
args: "test test/short-pass.ts --jobs=2",
73+
exit_code: 0,
74+
output: "test/short-pass-jobs-flag-with-numeric-value.out",
75+
});
76+
77+
itest!(jobs_flag_with_env_variable {
78+
args: "test test/short-pass.ts --jobs",
79+
envs: vec![("DENO_JOBS".to_owned(), "2".to_owned())],
80+
exit_code: 0,
81+
output: "test/short-pass.out",
82+
});
83+
84+
itest!(jobs_flag_with_numeric_value_and_env_var {
85+
args: "test test/short-pass.ts --jobs=2",
86+
envs: vec![("DENO_JOBS".to_owned(), "3".to_owned())],
87+
exit_code: 0,
88+
output: "test/short-pass-jobs-flag-with-numeric-value.out",
89+
});
90+
6591
itest!(load_unload {
6692
args: "test test/load_unload.ts",
6793
exit_code: 0,
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Warning: --jobs flag is deprecated. Use 'DENO_JOBS' environment variable instead.
2+
Check [WILDCARD]/test/pass.ts
3+
running 10 tests from ./test/pass.ts
4+
test 0 ... ok ([WILDCARD])
5+
test 1 ... ok ([WILDCARD])
6+
test 2 ... ok ([WILDCARD])
7+
test 3 ... ok ([WILDCARD])
8+
test 4 ... ok ([WILDCARD])
9+
test 5 ... ok ([WILDCARD])
10+
test 6 ... ok ([WILDCARD])
11+
test 7 ... ok ([WILDCARD])
12+
test 8 ...
13+
------- output -------
14+
console.log
15+
----- output end -----
16+
test 8 ... ok ([WILDCARD])
17+
test 9 ...
18+
------- output -------
19+
console.error
20+
----- output end -----
21+
test 9 ... ok ([WILDCARD])
22+
23+
ok | 10 passed | 0 failed ([WILDCARD])
24+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Warning: --jobs flag with numeric value is deprecated. Use 'DENO_JOBS' environment variable with --jobs flag instead.
2+
Check [WILDCARD]/test/short-pass.ts
3+
running 1 test from ./test/short-pass.ts
4+
test ... ok ([WILDCARD])
5+
6+
ok | 1 passed | 0 failed ([WILDCARD])
7+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Check [WILDCARD]/test/short-pass.ts
2+
running 1 test from ./test/short-pass.ts
3+
test ... ok ([WILDCARD])
4+
5+
ok | 1 passed | 0 failed ([WILDCARD])
6+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Deno.test("test", () => {});

0 commit comments

Comments
 (0)