-
Notifications
You must be signed in to change notification settings - Fork 613
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
Ensure that Jest testRegex catches all the specs #2204
Ensure that Jest testRegex catches all the specs #2204
Conversation
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.
/lgtm
We'll see if the tests still pass... :/ |
There are some test failures, I'll fix them. |
frontend/package.json
Outdated
@@ -43,7 +43,7 @@ | |||
"transformIgnorePatterns": [ | |||
"<rootDir>/node_modules/(?!(lodash-es|@console|@novnc|@spice-project)/.*)" | |||
], | |||
"testRegex": "/__tests__/.*\\.spec\\.(ts|tsx|js|jsx)$", | |||
"testRegex": "/__tests__/.*\\.(ts|tsx|js|jsx)$", |
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.
This can't be right. Don't we need spec
in there because for dev-console
we put non-test files inside the __tests__
dir as support utils or data.
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.
Exactly, we need this for all the monorepo tests, otherwise it blows up on test helpers (and rightly so).
$ yarn test packages
..
packages/dev-console/src/components/pipelines/__tests__/pipeline-mock.ts
..
Your test suite must contain at least one test.
We could use Jest projects feature, or just git-mv the 8 files in frontend/__tests__
to correctly follow the spec
convention.
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.
@vojtechszocs just make testRegex
an array. One for packages
and one for everything else.
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.
@vojtechszocs actually just move the files to the correct format and be done with it. It's where we want to go anyways.
/retest Please review the full test history for this PR and help us cut down flakes. |
8e7b3f3
to
7524302
Compare
PR updated, git-mv'ed above mentioned files to ensure they are matched by Jest. |
/retest |
frontend/__tests__/units.spec.js
Outdated
@@ -2,7 +2,7 @@ import * as _ from 'lodash-es'; | |||
|
|||
import { units, validate, convertToBaseValue } from '../public/components/utils/units'; | |||
|
|||
describe('units', () => { | |||
xdescribe('units', () => { |
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.
We should really try to fix these tests. How bad are the failures?
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.
/retest |
/assign @TheRealJon |
@christianvogt @alecmerdler @TheRealJon Tests are fixed now, can you please take a look if you have some time? |
Seems ok, but unsure of the history and ux expectation for the unit formatting. |
const {locales, ...rest} = _.defaults(options, { | ||
maximumFractionDigits: fractionDigits, | ||
maximumFractionDigits: 20, |
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.
What is the reason for this change? 20 seems like a big value, but maybe I'm misunderstanding this option.
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.
fraction digits are determined by round
function
const multiplier = Math.pow(10, fractionDigits || getDefaultFractionDigits(value)); |
formatValue
function is used only for formatting string part - I didnt want to change value here so I set maximumFractionDigits
to maximum that is allowed
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.
Do we need round
at all if we can use maximumFractionDigits
for formatting here?
This should at least have a comment explaining.
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.
humanize functions return object
value: number;
unit: string;
string: string;
at first we work on value
-> it gets rounded (result is number type) and then the rounded value is passed to formatValue
which is using Intl.NumberFormat.format
and the result is string type.
I we use only Intl.NumberFormat.format
then we would need to parse the resulting string back to number which seems a more clumsy to me.
I will add a comment explaining this if we decide to go with current approach
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 I'm still unclear why we need to change this implementation here. Is this fixing a bug, changing behavior, or just refactoring? Can you give an example of the before / after with this change?
Based on your description, I think the existing API is a bit confusing. I would expect
- A function that takes a string value with units and returns an object like
{value, unit}
- A function that takes the base, unitless value, picks the best unit, and formats it using
Intl.NumberFormat
and specifying significant digits - A function that takes
{value, unit}
and formats it usingIntl.NumberFormat
and specifying significant digits
I'm not proposing we make these changes in this PR, but we might look at refactoring this down the road.
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.
If we keep the fractionDigits
in Intl.NumberFormat
config and call humanize
with useRound=false
we will end up with value
not rounded, but string
rounded. Maybe that is not an issue, useRound=false
isnt even used anywhere in code right now and when we refactor things in the future we will either way end up with something different.
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.
If we keep the fractionDigits in Intl.NumberFormat config and call humanize with useRound=false we will end up with value not rounded, but string rounded.
This is exactly what I would expect :) I think it's a better API. Is this what the code was doing before?
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.
Ok :) Reverted the change. Before we started using Intl.NumberFormat
both value
and string
was the same (string
was just value
+ space
+ unit
), after Intl.NumberFormat
was introduced the things got different/tests started to fail so I wasnt sure if this change was on purpose or not. But I agree that it makes sense to keep the logic as is.
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.
OK, I see the complaint now. It's the the string value is rounded when useRound = false. Sorry I misunderstood.
I think the fix is to always round the humanized value and just remove useRound
if it's not used anywhere today. But that can be a follow on.
21c5ba2
to
d749c18
Compare
Fix units tests
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.
/approve
/lgtm
Looks like we have one test failure:
|
/lgtm cancel |
d749c18
to
25dbfce
Compare
sorry about that, i forgot to push latest changes, should be fine now. |
/test e2e-aws-console |
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.
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: spadgett, vojtechszocs The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Fixes CONSOLE-1658
The change in Jest
testRegex
made in commit b4bc8c9 caused some specs not to be executed.Files under
__tests__
are either actual tests or test helpers (utils, mocks, etc). Actual tests should havespec
in their filename. We want to co-locate test helpers with actual tests, but we also want Jest to not match those helpers.Above ^^ files have been git-mv'ed to contain
spec
in their filename.frontend/__tests__/units.spec.js
is still failing, so usingxdescribe
as a temporary fix. I've talked with @rawagner and he'll take a closer look on that.cc @jelkosz