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

[Metric] convert mocha tests to jest #54054

Merged
merged 15 commits into from
Jan 17, 2020

Conversation

nickofthyme
Copy link
Contributor

@nickofthyme nickofthyme commented Jan 6, 2020

Summary

  • Convert all mocha tests to jest
  • Add fixtures/* alias to typescript
  • Convert remaining javascript files to typescript

Checklist

For maintainers

@nickofthyme nickofthyme requested a review from a team as a code owner January 6, 2020 20:33
@nickofthyme nickofthyme added the release_note:skip Skip the PR/issue when compiling release notes label Jan 6, 2020
@nickofthyme nickofthyme requested a review from a team January 7, 2020 15:06
Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

LGTM besides some small open questions

});

it('should set the metric label and value', function() {
const metrics = metricController._processTableGroups({
// @ts-ignore
const metrics = metricVis.processTableGroups({
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a bit weird to test react components like this - could we change this to simple enzyme tests with a snapshot assertion instead? Then we don't have to call into the internal method.

@@ -0,0 +1,106 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to rename this to metric_vis_type.test.ts? Just to have a mapping to the file its logic it is testing.

@@ -17,11 +17,14 @@
* under the License.
*/

import expect from '@kbn/expect';
import { MetricVisComponent } from '../components/metric_vis_controller';
// @ts-ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

leftover from the conversion?

const max = last<{ to: number }>(config.colorsRange).to;
const colors = this.getColors();
const labels = this.getLabels();
const metrics: any[] = []; // not yet typed
Copy link
Contributor

Choose a reason for hiding this comment

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

It's fine to postpone these types, but could you create a "dummy type" for it? export type MetricVisMetric = any and then use MetricVisMetric everywhere. By doing so it will get much easier to propagate the type through your code once it's added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great idea!

@@ -12,7 +12,8 @@
],
"test_utils/*": [
"src/test_utils/public/*"
]
],
"fixtures/*": ["src/fixtures/*"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need this alias? I don't know how much fixtures will be used in the future and IMHO it's better to only introduce these if they are really necessary - just using a relative import seems easier to me. But maybe I'm missing an aspect here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I was questioning whether to add this, but the fixtures files have the fixtures/ aliased paths in them so a relative import still fails. Do you think I should change all the paths in the fixtures files to be relative and get rid of this alias?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah good point. @elastic/kibana-operations do you have a suggestion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMHO I think we keep this for now until we phase out the fixtures completely. Mainly because I think it's strange to have a path alias in javascript that is not also in typescript.

@nickofthyme nickofthyme requested a review from a team as a code owner January 9, 2020 20:05
@nickofthyme
Copy link
Contributor Author

@elasticmachine merge upstream

@nickofthyme nickofthyme added v7.7.0 and removed v7.6.0 labels Jan 13, 2020
@nickofthyme
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

This LGTM - visualization still works and tests look good.

@nickofthyme
Copy link
Contributor Author

@elastic/kibana-operations & @elastic/kibana-app-arch could I get a review whenever you get a chance? Thanks

Copy link
Contributor

@lizozom lizozom left a comment

Choose a reason for hiding this comment

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

Code owner changes LGTM

@nickofthyme
Copy link
Contributor Author

Hey @spalger are you ok with the operations codeowner changes?

Copy link
Contributor

@tylersmalley tylersmalley left a comment

Choose a reason for hiding this comment

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

LGTM - really not sure how I feel about the fixtures but can't come up with a better solution.

@nickofthyme
Copy link
Contributor Author

@tylersmalley agreed, ideally we phase them out once the mocha tests are gone. Thanks 👍

@nickofthyme nickofthyme merged commit 119eabe into elastic:master Jan 17, 2020
@nickofthyme nickofthyme deleted the kpm/metric-mocha-to-jest branch January 17, 2020 18:00
@nickofthyme nickofthyme changed the title Kpm/metric mocha to jest [Metric] convert mocha tests to jest Jan 17, 2020
nickofthyme added a commit to nickofthyme/kibana that referenced this pull request Jan 17, 2020
* Add fixtures/* alias to tsconfig and jest config
* Convert metric tests to jest
* Convert remaining js files to ts
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

nickofthyme added a commit that referenced this pull request Jan 17, 2020
* Add fixtures/* alias to tsconfig and jest config
* Convert metric tests to jest
* Convert remaining js files to ts
gmmorris added a commit to gmmorris/kibana that referenced this pull request Jan 20, 2020
* upstream/master: (83 commits)
  [Reporting] Fix map tiles not loading by using Chrome's Remote Protocol (elastic#55137)
  [Data Plugin] combine autocomplete provider and suggestions provider (elastic#54451)
  resolves elastic#53038 - remove references to specific license levels (elastic#53858)
  highlighting rules should still know about url parts when in sql state (elastic#55200)
  [Metric] convert mocha tests to jest (elastic#54054)
  [skip-ci] Update vector styling docs for 7.6 UI changes and new features (elastic#55087)
  Fix enable API to schedule task after alert is updated (elastic#55095)
  chore(NA): add 7.6 branch to the list of backport branches (elastic#54998)
  Convert tests to jest in vis_type_timeseries/public & common folders (elastic#55023)
  [ML] Accessibility fix for structural markup on table rows (elastic#55075)
  [Mappings editor] include/exclude fields only support custom options (elastic#54949)
  [Vis] Move Timelion Vis to vis_type_timelion (elastic#52069)
  Deprecate `chrome.navlinks.update` and add documentation (elastic#54893)
  [ML] Single Metric Viewer: Fix time bounds with custom strings. (elastic#55045)
  [Vis: Default editor] EUIficate and Reactify the sidebar (elastic#49864)
  [Mappings editor] Fix cannot set boolean value for "null_value" param (elastic#55015)
  [SIEM] Adds support for apm-* to the network map (elastic#54876)
  [Reporting] Define shims of legacy dependencies (elastic#54082)
  Resolver is overflow: hidden to prevent obscured elements from showing up (elastic#55076)
  Upgraded EUI to 18.2.1 (elastic#55090)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:New Platform release_note:skip Skip the PR/issue when compiling release notes v7.7.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants