Skip to content

Commit 07c601e

Browse files
deokjinkimtargos
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 e26166f commit 07c601e

File tree

3 files changed

+4
-11
lines changed

3 files changed

+4
-11
lines changed

lib/internal/test_runner/runner.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ const {
4141
codes: {
4242
ERR_INVALID_ARG_TYPE,
4343
ERR_INVALID_ARG_VALUE,
44-
ERR_OUT_OF_RANGE,
4544
ERR_TEST_FAILURE,
4645
},
4746
} = require('internal/errors');
@@ -495,11 +494,7 @@ function run(options = kEmptyObject) {
495494
shard = { __proto__: null, index: shard.index, total: shard.total };
496495

497496
validateInteger(shard.total, 'options.shard.total', 1);
498-
validateInteger(shard.index, 'options.shard.index');
499-
500-
if (shard.index <= 0 || shard.total < shard.index) {
501-
throw new ERR_OUT_OF_RANGE('options.shard.index', `>= 1 && <= ${shard.total} ("options.shard.total")`, shard.index);
502-
}
497+
validateInteger(shard.index, 'options.shard.index', 1, shard.total);
503498

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

test/parallel/test-runner-cli.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ const testFixtures = fixtures.path('test-runner');
238238

239239
assert.strictEqual(child.status, 1);
240240
assert.strictEqual(child.signal, null);
241-
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/);
241+
assert.match(child.stderr.toString(), /The value of "options\.shard\.index" is out of range\. It must be >= 1 && <= 3\. Received 0/);
242242
const stdout = child.stdout.toString();
243243
assert.strictEqual(stdout, '');
244244
}

test/parallel/test-runner-run.mjs

+2-4
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,7 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
345345
}), {
346346
name: 'RangeError',
347347
code: 'ERR_OUT_OF_RANGE',
348-
// eslint-disable-next-line @stylistic/js/max-len
349-
message: 'The value of "options.shard.index" is out of range. It must be >= 1 && <= 6 ("options.shard.total"). Received 0'
348+
message: 'The value of "options.shard.index" is out of range. It must be >= 1 && <= 6. Received 0'
350349
});
351350
});
352351

@@ -360,8 +359,7 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
360359
}), {
361360
name: 'RangeError',
362361
code: 'ERR_OUT_OF_RANGE',
363-
// eslint-disable-next-line @stylistic/js/max-len
364-
message: 'The value of "options.shard.index" is out of range. It must be >= 1 && <= 6 ("options.shard.total"). Received 7'
362+
message: 'The value of "options.shard.index" is out of range. It must be >= 1 && <= 6. Received 7'
365363
});
366364
});
367365

0 commit comments

Comments
 (0)