File tree Expand file tree Collapse file tree 3 files changed +44
-4
lines changed Expand file tree Collapse file tree 3 files changed +44
-4
lines changed Original file line number Diff line number Diff line change @@ -331,9 +331,14 @@ changes:
331331 does not have a name.
332332* ` options ` {Object} Configuration options for the test. The following
333333 properties are supported:
334- * ` concurrency ` {number} The number of tests that can be run at the same time.
334+ * ` concurrency ` {number|boolean} If a number is provided,
335+ then that many tests would run in parallel.
336+ If truthy, it would run (number of cpu cores - 1)
337+ tests in parallel.
338+ For subtests, it will be ` Infinity ` tests in parallel.
339+ If falsy, it would only run one test at a time.
335340 If unspecified, subtests inherit this value from their parent.
336- ** Default:** ` 1 ` .
341+ ** Default:** ` false ` .
337342 * ` only ` {boolean} If truthy, and the test context is configured to run
338343 ` only ` tests, then this test will be run. Otherwise, the test is skipped.
339344 ** Default:** ` false ` .
Original file line number Diff line number Diff line change 44 ArrayPrototypeShift,
55 ArrayPrototypeUnshift,
66 FunctionPrototype,
7+ MathMax,
78 Number,
89 PromisePrototypeThen,
910 PromiseResolve,
@@ -52,8 +53,7 @@ const noop = FunctionPrototype;
5253const isTestRunner = getOptionValue ( '--test' ) ;
5354const testOnlyFlag = ! isTestRunner && getOptionValue ( '--test-only' ) ;
5455// TODO(cjihrig): Use uv_available_parallelism() once it lands.
55- const rootConcurrency = isTestRunner ? cpus ( ) . length : 1 ;
56-
56+ const rootConcurrency = isTestRunner ? MathMax ( cpus ( ) . length - 1 , 1 ) : 1 ;
5757const kShouldAbort = Symbol ( 'kShouldAbort' ) ;
5858
5959
@@ -151,6 +151,12 @@ class Test extends AsyncResource {
151151
152152 if ( isUint32 ( concurrency ) && concurrency !== 0 ) {
153153 this . concurrency = concurrency ;
154+ } else if ( typeof concurrency === 'boolean' ) {
155+ if ( concurrency ) {
156+ this . concurrency = isTestRunner ? MathMax ( cpus ( ) . length - 1 , 1 ) : Infinity ;
157+ } else {
158+ this . concurrency = 1 ;
159+ }
154160 }
155161
156162 if ( timeout != null && timeout !== Infinity ) {
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+ require ( '../common' ) ;
3+ const { describe, it } = require ( 'node:test' ) ;
4+ const assert = require ( 'assert' ) ;
5+
6+ describe ( 'Concurrency option (boolean) = true ' , { concurrency : true } , ( ) => {
7+ let isFirstTestOver = false ;
8+ it ( 'should start the first test' , ( ) => new Promise ( ( resolve ) => {
9+ setImmediate ( ( ) => { isFirstTestOver = true ; resolve ( ) ; } ) ;
10+ } ) ) ;
11+ it ( 'should start before the previous test ends' , ( ) => {
12+ // Should work even on single core CPUs
13+ assert . strictEqual ( isFirstTestOver , false ) ;
14+ } ) ;
15+ } ) ;
16+
17+ describe (
18+ 'Concurrency option (boolean) = false ' ,
19+ { concurrency : false } ,
20+ ( ) => {
21+ let isFirstTestOver = false ;
22+ it ( 'should start the first test' , ( ) => new Promise ( ( resolve ) => {
23+ setImmediate ( ( ) => { isFirstTestOver = true ; resolve ( ) ; } ) ;
24+ } ) ) ;
25+ it ( 'should start after the previous test ends' , ( ) => {
26+ assert . strictEqual ( isFirstTestOver , true ) ;
27+ } ) ;
28+ }
29+ ) ;
You can’t perform that action at this time.
0 commit comments