Skip to content
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

Merged
merged 3 commits into from
Aug 16, 2019

Conversation

vojtechszocs
Copy link
Contributor

@vojtechszocs vojtechszocs commented Jul 29, 2019

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 have spec in their filename. We want to co-locate test helpers with actual tests, but we also want Jest to not match those helpers.

$ NON_SPEC_FILES=`find . -type f -regex '.*/__tests__/.*' | grep -vF 'node_modules' | grep -vF '.spec.'`
$ grep -l 'describe' $NON_SPEC_FILES 
./__tests__/components/utils/datetime.ts
./__tests__/public/co-fetch.js
./__tests__/resource.js
./__tests__/selector-requirement.js
./__tests__/selector.js
./__tests__/container.ts
./__tests__/probe.ts
./__tests__/units.js

Above ^^ files have been git-mv'ed to contain spec in their filename.

frontend/__tests__/units.spec.js is still failing, so using xdescribe as a temporary fix. I've talked with @rawagner and he'll take a closer look on that.

cc @jelkosz

@openshift-ci-robot openshift-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jul 29, 2019
Copy link
Member

@spadgett spadgett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 29, 2019
@spadgett
Copy link
Member

We'll see if the tests still pass... :/

@vojtechszocs
Copy link
Contributor Author

There are some test failures, I'll fix them.

@@ -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)$",
Copy link
Contributor

@christianvogt christianvogt Jul 29, 2019

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Jul 29, 2019
@vojtechszocs
Copy link
Contributor Author

PR updated, git-mv'ed above mentioned files to ensure they are matched by Jest.

@vojtechszocs vojtechszocs changed the title Revert to original Jest testRegex Ensure that Jest testRegex catches all the specs Jul 29, 2019
@spadgett
Copy link
Member

/retest

@@ -2,7 +2,7 @@ import * as _ from 'lodash-es';

import { units, validate, convertToBaseValue } from '../public/components/utils/units';

describe('units', () => {
xdescribe('units', () => {
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rawagner has fixed the tests 🎉

He said the problem originates from commit b14d83b (change in round function).

@openshift-ci-robot openshift-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. component/core Related to console core functionality and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jul 30, 2019
@vojtechszocs
Copy link
Contributor Author

/retest

@spadgett
Copy link
Member

/assign @TheRealJon

@vojtechszocs
Copy link
Contributor Author

vojtechszocs commented Aug 1, 2019

@christianvogt @alecmerdler @TheRealJon

Tests are fixed now, can you please take a look if you have some time?

@christianvogt
Copy link
Contributor

Seems ok, but unsure of the history and ux expectation for the unit formatting.

frontend/public/components/utils/units.js Show resolved Hide resolved
frontend/public/components/utils/units.js Show resolved Hide resolved
const {locales, ...rest} = _.defaults(options, {
maximumFractionDigits: fractionDigits,
maximumFractionDigits: 20,
Copy link
Member

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.

Copy link
Contributor

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));
and 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

Copy link
Member

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.

Copy link
Contributor

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

Copy link
Member

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 using Intl.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.

Copy link
Contributor

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.

Copy link
Member

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?

Copy link
Contributor

@rawagner rawagner Aug 15, 2019

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.

Copy link
Member

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.

Copy link
Member

@spadgett spadgett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve
/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 15, 2019
@spadgett spadgett added this to the v4.2 milestone Aug 15, 2019
@spadgett
Copy link
Member

Looks like we have one test failure:

FAIL __tests__/units.spec.js (91.846s)
  ● units › should humanize numeric values › 0.1234 into 0.1234 

@spadgett
Copy link
Member

/lgtm cancel
as we have a test failure

@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Aug 15, 2019
@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 16, 2019
@rawagner
Copy link
Contributor

sorry about that, i forgot to push latest changes, should be fine now.

@rawagner
Copy link
Contributor

/test e2e-aws-console

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 16, 2019
Copy link
Member

@spadgett spadgett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

@openshift-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit 9dc137f into openshift:master Aug 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. component/core Related to console core functionality lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants