| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -331,9 +331,14 @@ changes: | |||
| 331 | 331 | does not have a name. | |
| 332 | 332 | * `options` {Object} Configuration options for the test. The following | |
| 333 | 333 | 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. | ||
| 335 | 340 | If unspecified, subtests inherit this value from their parent. | |
| 336 | - **Default:** `1`. | ||
| 341 | + **Default:** `false`. | ||
| 337 | 342 | * `only` {boolean} If truthy, and the test context is configured to run | |
| 338 | 343 | `only` tests, then this test will be run. Otherwise, the test is skipped. | |
| 339 | 344 | **Default:** `false`. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,7 @@ const { | |||
| 4 | 4 | ArrayPrototypeShift, | |
| 5 | 5 | ArrayPrototypeUnshift, | |
| 6 | 6 | FunctionPrototype, | |
| 7 | + MathMax, | ||
| 7 | 8 | Number, | |
| 8 | 9 | PromisePrototypeThen, | |
| 9 | 10 | PromiseResolve, | |
@@ -52,8 +53,7 @@ const noop = FunctionPrototype; | |||
| 52 | 53 | const isTestRunner = getOptionValue('--test'); | |
| 53 | 54 | const testOnlyFlag = !isTestRunner && getOptionValue('--test-only'); | |
| 54 | 55 | // 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; | ||
| 57 | 57 | const kShouldAbort = Symbol('kShouldAbort'); | |
| 58 | 58 | ||
| 59 | 59 | ||
@@ -151,6 +151,12 @@ class Test extends AsyncResource { | |||
| 151 | 151 | ||
| 152 | 152 | if (isUint32(concurrency) && concurrency !== 0) { | |
| 153 | 153 | 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 | + } | ||
| 154 | 160 | } | |
| 155 | 161 | ||
| 156 | 162 | if (timeout != null && timeout !== Infinity) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,29 @@ | |||
| 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 | + ); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments