-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(smokehouse): +/- operator #7343
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,8 +34,11 @@ const PROTOCOL_TIMEOUT_EXIT_CODE = 67; | |
const PAGE_HUNG_EXIT_CODE = 68; | ||
const INSECURE_DOCUMENT_REQUEST_EXIT_CODE = 69; | ||
const RETRIES = 3; | ||
const NUMERICAL_EXPECTATION_REGEXP = /^(<=?|>=?)((\d|\.)+)$/; | ||
const VERBOSE = Boolean(process.env.LH_SMOKE_VERBOSE); | ||
const NUMBER_REGEXP = /(?:\d|\.)+/.source; | ||
const OPS_REGEXP = /<=?|>=?|\+\/-/.source; | ||
const NUMERICAL_EXPECTATION_REGEXP = | ||
new RegExp(`^(${NUMBER_REGEXP})?\\s?(${OPS_REGEXP})\\s?(${NUMBER_REGEXP})$`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this clearer than There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, but I'm not sure I'd call either of them super clear ;) maybe we can at least get a comment here explaining what's going on in english?
|
||
|
||
/** | ||
* Attempt to resolve a path locally. If this fails, attempts to locate the path | ||
|
@@ -149,17 +152,19 @@ function runLighthouse(url, configPath, isDebug) { | |
function matchesExpectation(actual, expected) { | ||
if (typeof actual === 'number' && NUMERICAL_EXPECTATION_REGEXP.test(expected)) { | ||
const parts = expected.match(NUMERICAL_EXPECTATION_REGEXP); | ||
const operator = parts[1]; | ||
const number = parseFloat(parts[2]); | ||
const operator = parts[2]; | ||
const numbers = [parts[1], parts[3]].filter(p => typeof p !== 'undefined').map(parseFloat); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it'd make more sense if you nixed the filter and made it explicit const [prefixNumber, operator, postfixNumber] = parts
// optional named descriptor, though IMO probably unnecessary and might just add cognitive overload
const targetNumber = typeof prefixNumber === 'undefined' ? postfixNumber : prefixNumber There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. relying on implicit string -> float conversion. doesn't bother me here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I forgot about the maybe my "optional named descriptor" is more important to me than I realized... haha There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ha, it would probably have been simpler to just move off the switch statement :P |
||
switch (operator) { | ||
case '>': | ||
return actual > number; | ||
return actual > numbers[0]; | ||
case '>=': | ||
return actual >= number; | ||
return actual >= numbers[0]; | ||
case '<': | ||
return actual < number; | ||
return actual < numbers[0]; | ||
case '<=': | ||
return actual <= number; | ||
return actual <= numbers[0]; | ||
case '+/-': | ||
return Math.abs(actual - numbers[0]) <= numbers[1]; | ||
default: | ||
throw new Error(`unexpected operator ${operator}`); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so nice!