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 <cjihrig@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent e26166f commit 07c601e

3 files changed

Lines changed: 4 additions & 11 deletions

File tree

‎lib/internal/test_runner/runner.js‎

Lines changed: 1 addition & 6 deletions
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-
thrownewERR_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
thrownewERR_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
@@ -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(),/Thevalueof"options\.shard\.index"isoutofrange\.Itmustbe>=1&&<=3\("options\.shard\.total"\)\.Received0/);
241+
assert.match(child.stderr.toString(),/Thevalueof"options\.shard\.index"isoutofrange\.Itmustbe>=1&&<=3\.Received0/);
242242
conststdout=child.stdout.toString();
243243
assert.strictEqual(stdout,'');
244244
}

‎test/parallel/test-runner-run.mjs‎

Lines changed: 2 additions & 4 deletions
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)