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

[Enterprise Search] Jest config & handy Jest script #84839

Merged
merged 2 commits into from
Dec 17, 2020

Conversation

cee-chen
Copy link
Contributor

@cee-chen cee-chen commented Dec 2, 2020

Summary

  • Updates our new Jest config file to automatically report coverage (no more copying and pasting super long CLI commands!)
  • Because I'm very extra, I also added a shell script that makes the dev experience of running tests (& getting coverage) on a specific component folder easier. Example API:
# Run commands from the `enterprise_search` plugin folder root

# run and get coverage on all tests
sh jest.sh

# run and get coverage on specific folder
sh jest.sh public/applications/shared/http

Let me know what you think y'all!! 🙇‍♀️

Checklist

  • Documentation was added for features that require explanation or tutorials

@cee-chen cee-chen added Feature:Plugins release_note:skip Skip the PR/issue when compiling release notes v7.11.0 labels Dec 2, 2020
@cee-chen cee-chen requested a review from a team December 2, 2020 22:01
Copy link
Contributor

@scottybollinger scottybollinger left a comment

Choose a reason for hiding this comment

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

This is awesome! Thanks for making our lives easier!

🎉 🎉 🎉

@tylersmalley
Copy link
Contributor

Just a heads up, I am working on a global runner which I believe will solve some of the things you're doing here. My WIP is here: #84848

But essentially it will update yarn test:jest to find the right config file. You can either run it in the a folder within your plugin, or pass a path to your plugin to it.

@cee-chen
Copy link
Contributor Author

cee-chen commented Dec 2, 2020

Oooh!! Thanks so much Tyler! 🎉 I can definitely hang tight on this PR until yours is merged in and play around with that.

You can either run it in the a folder within your plugin,

Fantastic, this would be amazing! I've had some issues recently with collectCoverageFrom not really working as expected (it doesn't seem to listen to the roots setting, but seems to always require explicitly pathing from rootDir) and I'm hoping your PR might solve that. If I can get around not needing the jest.sh script I'll definitely be a happy camper.

@tylersmalley
Copy link
Contributor

Sounds great! Yeah, it should remove the need for the jest.sh file entirely, with the bonus it's able to be used across the repository. I am not sure abou the collectCoverageFrom issue you're referring to. Can you provide some reproduction details, or want to get on a quick Zoom to go over it?

@cee-chen cee-chen marked this pull request as draft December 3, 2020 23:05
@cee-chen cee-chen marked this pull request as ready for review December 16, 2020 00:33
@cee-chen cee-chen force-pushed the jest-config branch 2 times, most recently from 17c6fe2 to 93c6631 Compare December 16, 2020 01:13
@cee-chen
Copy link
Contributor Author

@tylersmalley The command works fantastic for only running tests within the current folder/subdir, but unfortunately I couldn't get the new yarn test:jest command quite working the way I wanted w/ collection coverage. The end result I'm after is running a single command and having it only report coverage for that folder, e.g.:

Unfortunately current behavior for running yarn test:jest --coverage from within subfolders still reports coverage for everything in the entire enterprise_search plugin, not just the current folder. yarn test:jest --collectCoverageFrom=./ doesn't seem to work either (I'm guessing because --collectCoverageFrom requires rootDir).

I opted to keep using the jest.sh script, because using it from the enterprise_search plugin dir allows tab to autocomplete folder names which is always nice. LMK if you see any issues or workarounds at all!

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Distributable file count

id before after diff
default 47280 48041 +761

History

  • 💚 Build #94784 succeeded 93c663116ad44fdaf7606cdeee2fb9c8189ee10b
  • 💚 Build #91542 succeeded b747758a7f29e5ecff50306301d8d54c01fb09b0

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

@@ -8,4 +8,11 @@ module.exports = {
preset: '@kbn/test',
rootDir: '../../..',
roots: ['<rootDir>/x-pack/plugins/enterprise_search'],
collectCoverage: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you want to enable coverage by default. In your jest.sh file you can pass --coveage to do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, from a team perspective I'd prefer it for this project - coverage is fairly important to us and something I want our front end devs to always have in front of them.

If this has implications for CI or affects processes outside just our team/code though I can definitely turn it off and only set it in jest.sh - if not, I'd prefer to leave it as the default

Copy link
Contributor

Choose a reason for hiding this comment

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

I appreciate the importance of code coverage. While it won't have an impact on CI it does impact the default experience of anyone running yarn jest:test within the plugin. It will by default include code coverage for the entire plugin which requires a lot of scrolling to get to the normal output.

I will note that we are working on having code coverage reports/metrics as part of the pull request details.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While it won't have an impact on CI it does impact the default experience of anyone running yarn jest:test within the plugin

This should mostly be just Enterprise Search frontend devs though, right? In which case our team would fully expect this behavior. Is the concern for other non-Enterprise Search devs who need to make changes to our files/repo? (e.g., Kibana ops, etc.) That's definitely valid if so, but I would argue that it's a minor nuisance at worst for non-Enterprise Search devs who rarely need to make changes / run tests directly on our repo, but it's a major quality of life default for Enterprise Search devs since we're working on our code constantly and essentially always want to see accompanying coverage %s when we're running tests.

I will note that we are working on having code coverage reports/metrics as part of the pull request details.

Oh wow, that's amazing! I love developing on the Kibana platform so much, y'all just continue to be blow me away 🎉 Just curious, will the code coverage report for the touched files in the PR only, or reported based on the nearest jest config file (i.e. the entire plugin)?

Copy link
Contributor

Choose a reason for hiding this comment

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

This should mostly be just Enterprise Search frontend devs though, right? In which case our team would fully expect this behavior. Is the concern for other non-Enterprise Search devs who need to make changes to our files/repo? (e.g., Kibana ops, etc.) That's definitely valid if so, but I would argue that it's a minor nuisance at worst for non-Enterprise Search devs who rarely need to make changes / run tests directly on our repo, but it's a major quality of life default for Enterprise Search devs since we're working on our code constantly and essentially always want to see accompanying coverage %s when we're running tests.

Sounds like you have thought it through. I was just raising to make sure you're aware and sounds like this is what you expect. 👍

Oh wow, that's amazing! I love developing on the Kibana platform so much, y'all just continue to be blow me away tada Just curious, will the code coverage report for the touched files in the PR only, or reported based on the nearest jest config file (i.e. the entire plugin)?

It will be for the touched files. I really feel that is where the value of a code coverage report comes in, and it must be available at review time. The first step of this is to include the change as part of the metrics. However, we intend to iterate on this over time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will be for the touched files. I really feel that is where the value of a code coverage report comes in, and it must be available at review time.

Love it, that's totally what I was hoping for! Can't wait to see it happen, I'll definitely owe you some beers at the next all hands (whenever that is, haha 🍻 )

Copy link
Member

Choose a reason for hiding this comment

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

95% of the time that I'm running jest it's with the --watch flag, in which case, I do not need coverage reports, and probably don't want them to be run if it slows down the speed for tests. Do you know what effect this has on that use case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JasonStoltz With --watch on, it reports coverage for only the file that you touched:

That was on a server ts file, when I made changes on a Kea logic file and on a component tsx file, I saw some different/odd behavior (all 0s) but still nothing (IMO) that would significantly affect speed since coverage was still only being reported for 1 file vs the entire plugin.

I'm going to go ahead and merge this plugin in now as a heads up since it's been open a while - if you see significant performance issues due to text coverage reports, definitely let me know and we can continue to adjust.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, well that is actually really rad if it only reports coverage on the file you touched. That's a big plus. I was seeing different behavior when I tried it out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's different now with Tyler's changes + (perhaps?) the jest config changes in this PR - definitely feel free to ping if you you see otherwise locally on latest master!

@@ -8,4 +8,11 @@ module.exports = {
preset: '@kbn/test',
rootDir: '../../..',
roots: ['<rootDir>/x-pack/plugins/enterprise_search'],
collectCoverage: true,
coverageReporters: ['text'],
collectCoverageFrom: [
Copy link
Contributor

Choose a reason for hiding this comment

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

Passing this through the CLI will overwrite this setting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right yeah, overriding this setting via CLI is intentional for reporting specific folder coverage. Do you see that as being an issue?

Copy link
Contributor

Choose a reason for hiding this comment

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

I just wanted to point it out to make sure it's not being set if it's not intentionally used. Setting it here does deviate from the defaults of the preset defined 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.

Oooh, nice - I really like those presets, I wonder if there's any easy way to merge those in here 🤔 This collectCoverageFrom is being intentionally used here, essentially what I wanted was to to skip reporting for our public/plugin.ts and server/plugin.ts files (AFAIK there's no real meaningful way to write unit tests for those files, correct me if I'm wrong).

@tylersmalley
Copy link
Contributor

@constancecchen, thanks for the clairification. I believe this is something we could add to our wrapper. It does get a bit complicated as we will need to merge in the coverage settings from the project config or the jest-preset but it could be done. Mind creating an issue for it so we can track?

@cee-chen
Copy link
Contributor Author

Yes, no problem at all! Here it is: #86199

No rush on it as well, I'm personally super happy with the existing yarn test:jest and using a shortcut/script file for now.

@cee-chen cee-chen merged commit 694bbd4 into elastic:master Dec 17, 2020
@cee-chen cee-chen deleted the jest-config branch December 17, 2020 16:19
@cee-chen cee-chen added v7.12.0 and removed v7.11.0 labels Dec 17, 2020
cee-chen pushed a commit that referenced this pull request Dec 17, 2020
* Update Jest config to automatically report coverage

- No more super intricate yarn commands! Hooray

* Add handy shell script for running tests & coverage on specific folders/subdirectories
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Plugins release_note:skip Skip the PR/issue when compiling release notes v7.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants