Skip to content

Commit 9a36258

Browse files
deokjinkimmarco-ippolito
authored andcommitted
test_runner: refactor to use min/max of validateInteger
Instead of additional `if` statement, use min/max of `validateInteger` for `shard.index`. PR-URL: #53148 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent 2bcce32 commit 9a36258

File tree

3 files changed

+4
-10
lines changed

3 files changed

+4
-10
lines changed

lib/internal/test_runner/runner.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,7 @@ function run(options) {
536536
shard = { __proto__: null, index: shard.index, total: shard.total };
537537

538538
validateInteger(shard.total, 'options.shard.total', 1);
539-
validateInteger(shard.index, 'options.shard.index');
540-
541-
if (shard.index <= 0 || shard.total < shard.index) {
542-
throw new ERR_OUT_OF_RANGE('options.shard.index', `>= 1 && <= ${shard.total} ("options.shard.total")`, shard.index);
543-
}
539+
validateInteger(shard.index, 'options.shard.index', 1, shard.total);
544540

545541
if (watch) {
546542
throw new ERR_INVALID_ARG_VALUE('options.shard', watch, 'shards not supported with watch mode');

test/parallel/test-runner-cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ const testFixtures = fixtures.path('test-runner');
239239

240240
assert.strictEqual(child.status, 1);
241241
assert.strictEqual(child.signal, null);
242-
assert.match(child.stderr.toString(), /The value of "options\.shard\.index" is out of range\. It must be >= 1 && <= 3 \("options\.shard\.total"\)\. Received 0/);
242+
assert.match(child.stderr.toString(), /The value of "options\.shard\.index" is out of range\. It must be >= 1 && <= 3\. Received 0/);
243243
const stdout = child.stdout.toString();
244244
assert.strictEqual(stdout, '');
245245
}

test/parallel/test-runner-run.mjs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,7 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
350350
}), {
351351
name: 'RangeError',
352352
code: 'ERR_OUT_OF_RANGE',
353-
// eslint-disable-next-line @stylistic/js/max-len
354-
message: 'The value of "options.shard.index" is out of range. It must be >= 1 && <= 6 ("options.shard.total"). Received 0'
353+
message: 'The value of "options.shard.index" is out of range. It must be >= 1 && <= 6. Received 0'
355354
});
356355
});
357356

@@ -365,8 +364,7 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
365364
}), {
366365
name: 'RangeError',
367366
code: 'ERR_OUT_OF_RANGE',
368-
// eslint-disable-next-line @stylistic/js/max-len
369-
message: 'The value of "options.shard.index" is out of range. It must be >= 1 && <= 6 ("options.shard.total"). Received 7'
367+
message: 'The value of "options.shard.index" is out of range. It must be >= 1 && <= 6. Received 7'
370368
});
371369
});
372370

0 commit comments

Comments
 (0)