-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d90a70b
Switch pre-commit hook to pre-push
cee-chen c278544
Update `test-staged` to look at all commits from main, not just local…
cee-chen 4fb17b8
Use simpler `--changedSince` jest flag
cee-chen a18b6e3
[EuiCard] Fix imports pointed directly at `src/components/`
cee-chen 5d7a24d
[EuiPopover] Fix test import pointed at `src/components`
cee-chen 1063a24
[EuiProvider] Fix imports pointed at `src/components`
cee-chen f80952b
[src-docs] Fix import string somehow triggering bizarre Jest find rel…
cee-chen e4b32fe
Fix `src/test` imports pointed at `src/components/`
cee-chen 9b7f276
Add regression test for Jest `--findRelatedTests` behavior
cee-chen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,6 @@ | ||
| const { execSync } = require('child_process'); | ||
|
|
||
| // find names of staged files | ||
| const stagedFiles = execSync('git diff --cached --name-only --diff-filter=ACMR') | ||
| .toString() | ||
| .split(/[\r\n]+/g); | ||
|
|
||
| // execute tests related to the staged files | ||
| execSync(`yarn test-unit --findRelatedTests ${stagedFiles.join(' ')}`, { | ||
| // https://jestjs.io/docs/cli#--changedsince | ||
| execSync(`yarn test-unit --changedSince main`, { | ||
| stdio: 'inherit', | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| const { execSync } = require('child_process'); | ||
| const path = require('path'); | ||
| const euiRoot = path.resolve(__dirname, '../../'); // NOTE: CI lists the EUI project root as app/ instead of eui/ | ||
|
|
||
| describe('test-staged.js', () => { | ||
| it('does not have --findRelatedTests regressions due to imports from src/components', () => { | ||
| 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(); | ||
|
Comment on lines
+7
to
+20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an awesome way to test local infrastructure! |
||
|
|
||
| expect(output[2]).toBeUndefined(); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.tsxwhich 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
--findRelatedTestsand--changedSinceare failing because of several instances where we import from the top levelcomponents/index.ts, which causes the jest dependency tree to always resolve the wholesrc/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?
Uh oh!
There was an error while loading. Please reload this page.
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.
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
-nto 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.