review feedback

This commit is contained in:
Max Schmitt 2024-06-19 18:03:31 +02:00
parent 2f6ca92cfe
commit 4c11c9e854
2 changed files with 5 additions and 6 deletions

View file

@ -220,10 +220,9 @@ function parseWorkers(workers: string) {
const cpus = os.cpus().length;
return Math.max(1, Math.floor(cpus * (percentage / 100)));
}
const parsedWorkers = parseInt(workers, 10);
if (isNaN(parsedWorkers))
if (/[^0-9]/.test(workers))
throw new Error(`Workers ${workers} must be a number or percentage.`);
return parsedWorkers;
return parseInt(workers, 10);
}
function resolveProjectDependencies(projects: FullProjectInternal[]) {

View file

@ -340,7 +340,7 @@ class OptionValidators {
if (isNaN(parsed))
throw new InvalidArgumentError('Not a number.');
if (options.min !== undefined && parsed < options.min)
throw new InvalidArgumentError(`Expected a number greater than ${options.min}.`);
throw new InvalidArgumentError(`Expected a number greater or equal than ${options.min}.`);
if (options.max !== undefined && parsed > options.max)
throw new InvalidArgumentError(`Expected a number less than ${options.max}.`);
return value;
@ -348,7 +348,7 @@ class OptionValidators {
static validateWorkers(value: string): string {
if (value[value.length - 1] === '%') {
OptionValidators.validateNumber(value, { min: 1, max: 100 });
OptionValidators.validateNumber(value.slice(0, -1), { min: 1, max: 100 });
return value;
}
OptionValidators.validateNumber(value, { min: 1 });
@ -384,7 +384,7 @@ const testOptions: [string, string, ((value: string) => string | number)?][] = [
['--pass-with-no-tests', `Makes test run succeed even if no tests were found`],
['--project <project-name...>', `Only run tests from the specified list of projects, supports '*' wildcard (default: run all projects)`],
['--quiet', `Suppress stdio`],
['--repeat-each <N>', `Run each test N times (default: 1)`, value => OptionValidators.validateNumber(value, { min: 0 })],
['--repeat-each <N>', `Run each test N times (default: 1)`, value => OptionValidators.validateNumber(value, { min: 1 })],
['--reporter <reporter>', `Reporter to use, comma-separated, can be ${builtInReporters.map(name => `"${name}"`).join(', ')} (default: "${defaultReporter}")`],
['--retries <retries>', `Maximum retry count for flaky tests, zero for no retries (default: no retries)`, value => OptionValidators.validateNumber(value, { min: 0 })],
['--shard <shard>', `Shard tests and execute only the selected shard, specify in the form "current/all", 1-based, for example "3/5"`, OptionValidators.validateShard],