-
Notifications
You must be signed in to change notification settings - Fork 862
Switch pre-commit hook to pre-push; fix Jest --findRelatedTests behavior
#7163
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
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.
Couple quick notes - I played around with trying to keep the idea of the "test only files in the commit(s) as opposed to every single test" with the following commands:
git diff main...HEADyarn test-unit --changedSince main(docs)
Unfortunately, when I tested both by adding a small comment to, e.g. collapsible_nav_beta.tsx which no other component in the EUI library imports, Jest's logic for determining related tests seemed to go haywire and it started running thousands of other unrelated tests.
I'm not totally sure why the above was happening, but I don't think it's super worth investigating why (unless someone else can figure it out in under 30 mins here). CI will catch any test failures in any case and we're at least on-par with Kibana in that regard.
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.
@tkajtoch has discovered that Jest's --findRelatedTests and --changedSince are failing because of several instances where we import from the top level components/index.ts, which causes the jest dependency tree to always resolve the whole src/ directory.
I'll look into fixing that and linting for it separately from this PR, but out of curiosity, how do you all feel about running test locally on push as opposed to in CI? Do we definitely still want that, or stick to only linting?
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.
Actually, on second thought, I do think we do have to run tests on some hook before it reaches remote, regardless of EUI friction. The use case I'm thinking of here is open source/community non-Elastic developers who contribute to EUI - CI doesn't run for them automatically, so they lose the test feedback if we drop this from our pre-PR hooks.
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.
Actually, on second thought, I do think we do have to run tests on some hook before it reaches remote
If it has to be done, I think pre-push is the right place to have it. If the friction becomes too much, we can still use -n to skip the tests and allow CI to take care of it.
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.
I concur that pre-push strikes a good balance. If I'm moving fast and making a lot of atomic commits, I tend to skip the test run pre-commit, then forget to run tests before pushing and end up spending more time if the CI fails. Having that scoped test run before code makes it to the full job may take an extra 5-10 minutes, but end up saving 30 or more.
which messes up Jest's logic for finding related tests
which messes up Jest's logic for finding related tests
…ated tests bug?? - the `require`->`import` changes are syntactical sugar only, the main fix is line 44 (and no I don't understand why Jest is looking at strings lol)
eea7a33 to
f80952b
Compare
- which again, greatly messes up Jest's find related tests logic
pre-commit hook to pre-pushpre-commit hook to pre-push; fix Jest --findRelatedTests behavior
977862c to
66ce161
Compare
- a lint rule might be better long-term, but this will at least warn us if our hook starts running extra tests again
28476ad to
9b7f276
Compare
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_7163/ |
💚 Build Succeeded
History
cc @cee-chen |
|
@elastic/eui-team This is ready for re-review whenever! |
1Copenut
left a comment
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! I ran through your test case to see the console output. Very cool way to use the Jest CLI to confirm behavior.
This is going to be a net improvement by failing fast locally instead of failing slower on remote CI jobs.
| const outputString = execSync( | ||
| 'yarn test-unit --findRelatedTests --listTests src/components/beacon/beacon.tsx', | ||
| { cwd: euiRoot } | ||
| ).toString(); | ||
| const output = outputString | ||
| .split('\n') | ||
| .filter((item) => item.endsWith('test.tsx')); | ||
|
|
||
| expect( | ||
| output[0].endsWith('src/components/tour/tour_step.test.tsx') | ||
| ).toBeTruthy(); | ||
| expect( | ||
| output[1].endsWith('src/components/beacon/beacon.test.tsx') | ||
| ).toBeTruthy(); |
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 is an awesome way to test local infrastructure!
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.
I concur that pre-push strikes a good balance. If I'm moving fast and making a lot of atomic commits, I tend to skip the test run pre-commit, then forget to run tests before pushing and end up spending more time if the CI fails. Having that scoped test run before code makes it to the full job may take an extra 5-10 minutes, but end up saving 30 or more.
|
Thanks Trevor! I'm going to merge this in because honestly I'd really like this change for myself locally (will speed up my dev experience quite a bit, and save my wrist on extra clicks in vscode to commit w/ no verify 😅). But as always please feel free to leave post-merge comments and I can follow-up in another PR, or feel free to or open your own follow-up PR (mostly @tkajtoch, I do see your 👀 reaction). |
Summary
After a recent meeting, the EUI team discussed the friction point of the current
pre-commithook and that we feel it currently hinders developers more than it helps. We agreed to move it to apre-pushhook instead,and additionally switch it to only linting and not running unit tests.(see below git thread)Note - if absolutely necessary, this hook can be skipped via
git push --no-verify.QA
NOTE: Once this PR merges, devs will need to manually run
rm -rf .git/hooks/pre-commitfrom the EUI project rootGeneral checklist
N/A, tech debt/dev-only