| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,6 +19,7 @@ const { once } = require('events'); | |||
| 19 | 19 | const { AbortController } = require('internal/abort_controller'); | |
| 20 | 20 | const { | |
| 21 | 21 | codes: { | |
| 22 | + ERR_INVALID_ARG_TYPE, | ||
| 22 | 23 | ERR_TEST_FAILURE, | |
| 23 | 24 | }, | |
| 24 | 25 | kIsNodeError, | |
@@ -33,9 +34,9 @@ const { | |||
| 33 | 34 | } = require('internal/util'); | |
| 34 | 35 | const { isPromise } = require('internal/util/types'); | |
| 35 | 36 | const { | |
| 36 | - isUint32, | ||
| 37 | 37 | validateAbortSignal, | |
| 38 | 38 | validateNumber, | |
| 39 | + validateUint32, | ||
| 39 | 40 | } = require('internal/validators'); | |
| 40 | 41 | const { setTimeout } = require('timers/promises'); | |
| 41 | 42 | const { TIMEOUT_MAX } = require('internal/timers'); | |
@@ -149,14 +150,23 @@ class Test extends AsyncResource { | |||
| 149 | 150 | this.timeout = parent.timeout; | |
| 150 | 151 | } | |
| 151 | 152 | ||
| 152 | - if (isUint32(concurrency) && concurrency !== 0) { | ||
| 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 | - } | ||
| 153 | + switch (typeof concurrency) { | ||
| 154 | + case 'number': | ||
| 155 | + validateUint32(concurrency, 'options.concurrency', 1); | ||
| 156 | + this.concurrency = concurrency; | ||
| 157 | + break; | ||
| 158 | + | ||
| 159 | + case 'boolean': | ||
| 160 | + if (concurrency) { | ||
| 161 | + this.concurrency = isTestRunner ? MathMax(cpus().length - 1, 1) : Infinity; | ||
| 162 | + } else { | ||
| 163 | + this.concurrency = 1; | ||
| 164 | + } | ||
| 165 | + break; | ||
| 166 | + | ||
| 167 | + default: | ||
| 168 | + if (concurrency != null) | ||
| 169 | + throw new ERR_INVALID_ARG_TYPE('options.concurrency', ['boolean', 'number'], concurrency); | ||
| 160 | 170 | } | |
| 161 | 171 | ||
| 162 | 172 | if (timeout != null && timeout !== Infinity) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,3 +13,14 @@ const test = require('node:test'); | |||
| 13 | 13 | // Valid values should not throw. | |
| 14 | 14 | test({ timeout }); | |
| 15 | 15 | }); | |
| 16 | + | ||
| 17 | + [Symbol(), {}, [], () => {}, 1n, '1'].forEach((concurrency) => { | ||
| 18 | + assert.throws(() => test({ concurrency }), { code: 'ERR_INVALID_ARG_TYPE' }); | ||
| 19 | + }); | ||
| 20 | + [-1, 0, 1.1, -Infinity, NaN, 2 ** 33, Number.MAX_SAFE_INTEGER].forEach((concurrency) => { | ||
| 21 | + assert.throws(() => test({ concurrency }), { code: 'ERR_OUT_OF_RANGE' }); | ||
| 22 | + }); | ||
| 23 | + [null, undefined, 1, 2 ** 31, true, false].forEach((concurrency) => { | ||
| 24 | + // Valid values should not throw. | ||
| 25 | + test({ concurrency }); | ||
| 26 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments