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 targos committed Jun 3, 2024
1 parent e26166f commit 07c601e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
7 changes: 1 addition & 6 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ const {
codes: {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_OUT_OF_RANGE,
ERR_TEST_FAILURE,
},
} = require('internal/errors');
Expand Down Expand Up @@ -495,11 +494,7 @@ function run(options = kEmptyObject) {
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 @@ -238,7 +238,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 @@ -345,8 +345,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 @@ -360,8 +359,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 07c601e

Please sign in to comment.