test_runner: validate `timeout` option · nodejs/node@f980201 · GitHub
Skip to content

Commit f980201

Browse files
aduh95danielleadams
authored andcommitted
test_runner: validate timeout option
PR-URL: #43843 Reviewed-By: Feng Yu <F3n67u@outlook.com>
1 parent 2266a4b commit f980201

3 files changed

Lines changed: 33 additions & 3 deletions

File tree

lib/internal/test_runner/test.js

Lines changed: 8 additions & 2 deletions

lib/internal/validators.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const {
66
ArrayPrototypeJoin,
77
ArrayPrototypeMap,
88
NumberIsInteger,
9+
NumberIsNaN,
910
NumberMAX_SAFE_INTEGER,
1011
NumberMIN_SAFE_INTEGER,
1112
NumberParseInt,
@@ -115,9 +116,17 @@ function validateString(value, name) {
115116
throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
116117
}
117118

118-
function validateNumber(value, name) {
119+
function validateNumber(value, name, min = undefined, max) {
119120
if (typeof value !== 'number')
120121
throw new ERR_INVALID_ARG_TYPE(name, 'number', value);
122+
123+
if ((min != null && value < min) || (max != null && value > max) ||
124+
((min != null || max != null) && NumberIsNaN(value))) {
125+
throw new ERR_OUT_OF_RANGE(
126+
name,
127+
`${min != null ? `>= ${min}` : ''}${min != null && max != null ? ' && ' : ''}${max != null ? `<= ${max}` : ''}`,
128+
value);
129+
}
121130
}
122131

123132
const validateOneOf = hideStackFrames((value, name, oneOf) => {
Lines changed: 15 additions & 0 deletions

0 commit comments

Comments
 (0)