Skip to content

Commit

Permalink
test_runner: refactor to use min/max of validateInteger
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
deokjinkim authored and marco-ippolito committed Jul 19, 2024
1 parent 2bcce32 commit 9a36258
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
6 changes: 1 addition & 5 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,11 +536,7 @@ function run(options) {
shard = { __proto__: null, index: shard.index, total: shard.total };

validateInteger(shard.total, 'options.shard.total', 1);
validateInteger(shard.index, 'options.shard.index');

if (shard.index <= 0 || shard.total < shard.index) {
throw new ERR_OUT_OF_RANGE('options.shard.index', `>= 1 && <= ${shard.total} ("options.shard.total")`, shard.index);
}
validateInteger(shard.index, 'options.shard.index', 1, shard.total);

if (watch) {
throw new ERR_INVALID_ARG_VALUE('options.shard', watch, 'shards not supported with watch mode');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-runner-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ const testFixtures = fixtures.path('test-runner');

assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);
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/);
assert.match(child.stderr.toString(), /The value of "options\.shard\.index" is out of range\. It must be >= 1 && <= 3\. Received 0/);
const stdout = child.stdout.toString();
assert.strictEqual(stdout, '');
}
Expand Down
6 changes: 2 additions & 4 deletions test/parallel/test-runner-run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,7 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
}), {
name: 'RangeError',
code: 'ERR_OUT_OF_RANGE',
// eslint-disable-next-line @stylistic/js/max-len
message: 'The value of "options.shard.index" is out of range. It must be >= 1 && <= 6 ("options.shard.total"). Received 0'
message: 'The value of "options.shard.index" is out of range. It must be >= 1 && <= 6. Received 0'
});
});

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

Expand Down

0 comments on commit 9a36258

Please sign in to comment.