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

jest --changedFilesToContributeTo=origin/master #5188

Closed
wants to merge 3 commits into from

Conversation

alsuren
Copy link
Contributor

@alsuren alsuren commented Dec 27, 2017

Summary

I often have jest --watch running in a window, but sometimes I forget to look at it before committing, or I stage a bunch of changes that break tests, and it hides them from the test runner. This means that I often get surprised by CI test failures when I come to open pull requests.

This change allows you to write jest --watch --changedFilesSinceCommit=$LAST_MERGE_COMMIT to test your entire feature branch, but not the whole project.

LAST_MERGE_COMMIT can be written as HEAD^{/^Merge} or `git log --date-order --merges -1 --format=%H` on projects that use merge commits. On projects like jest that use linearised history, you might be able to get away with something like `git log --oneline --cherry --format=%H origin/master...HEAD | tail -n1`^ but I don't work on them often enough to know.

Test plan

I still need to write some integration tests for this (see TODO below) but I wanted to float the idea and get feedback before I got too invested in it.

To test this against the jest repo on my local machine, I have been running yarn run watch in one window, and yarn jest -- --onlyChanged --changedFilesSinceCommit=HEAD^^^^^^^^^ (if I add more ^s then I get more test suites run in my Test Suites: n passed, n total output.

TODO (feel free to add more):

  • integration test coverage
  • hg support (although git support didn't stop --changedFilesWithAncestor from being merged, by the look of it. Is this a requirement for merging, or is it enough to just explode gracefully?)
  • find a better name than --changedFilesSinceCommit (--changedFilesSinceRevision or something else?)
  • find a better name than findChangedFilesUsingCommand()?

@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

child.stdout.on('data', data => (stdout += data));
child.stderr.on('data', data => (stderr += data));
child.on('error', e => reject(e));
child.on('close', code => {
Copy link
Member

Choose a reason for hiding this comment

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

wow, we really should use execa or something...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this a refactor that you want me to include in my bug fix branch, or is it okay to just move the existing code about unchanged for now, and and backlog the execa change for later?

(git grep shows it up as a dependency of os-locale and lerna in yarn.lock, but isn't used directly by jest anywhere)

Copy link
Member

Choose a reason for hiding this comment

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

Sticking it in the backlog is no problem at all, and will keep this PR focused. So just keep the child_process stuff for now 🙂

@@ -12,6 +12,7 @@ import type {Path} from 'types/Config';
export type Options = {|
lastCommit?: boolean,
withAncestor?: boolean,
sinceCommit?: ?string,
Copy link
Member

Choose a reason for hiding this comment

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

? on both sides, does that mean anything? Ref #5176 (comment)

changedFilesWithAncestor: {
description:
'When used together with `--onlyChanged`, it runs tests ' +
'related to the current changes and the changes made in the last commit. ' +
'(NOTE: this only works for hg repos)',
Copy link
Member

Choose a reason for hiding this comment

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

Can this fix (thanks :D) be in a separate PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. I'll have a go at extracting it tomorrow (it's getting late here though).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

... okay so it turned out to be easier than I thought (#5189) but I am genuinely off to bed now.

@codecov-io
Copy link

codecov-io commented Dec 27, 2017

Codecov Report

Merging #5188 into master will decrease coverage by <.01%.
The diff coverage is 80%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5188      +/-   ##
==========================================
- Coverage   61.23%   61.23%   -0.01%     
==========================================
  Files         205      205              
  Lines        6891     6896       +5     
  Branches        4        3       -1     
==========================================
+ Hits         4220     4223       +3     
- Misses       2670     2672       +2     
  Partials        1        1
Impacted Files Coverage Δ
packages/jest-config/src/valid_config.js 100% <ø> (ø) ⬆️
packages/jest-config/src/index.js 25.92% <ø> (ø) ⬆️
packages/jest-cli/src/get_changed_files_promise.js 100% <ø> (ø) ⬆️
packages/jest-config/src/normalize.js 93.1% <ø> (ø) ⬆️
packages/jest-changed-files/src/hg.js 28.12% <0%> (-1.88%) ⬇️
packages/jest-changed-files/src/git.js 94.44% <100%> (+0.5%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6e788b1...933e33a. Read the comment docs.

@SimenB
Copy link
Member

SimenB commented Dec 27, 2017

I think this is a great idea! 🎉

The todos in the OP look fine to me.

Regarding mercurial support, I don't think it should be a blocker, but if you're able to add support for it, that would be great.

@cpojer
Copy link
Member

cpojer commented Jan 6, 2018

Can you rebase this and resolve the conflicts? Bonus points if you can also make this work for Mercurial before we merge this so that we keep consistency for people :)

@alsuren alsuren force-pushed the changed-files-refactor branch from 0b61468 to b5d751c Compare January 6, 2018 18:24
throw new Error(
'`changedFilesSinceCommit` is not supported in hg repos.',
);
}
let args = ['status', '-amnu'];
if (options && options.withAncestor) {
args.push('--rev', 'ancestor(.^)');
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've asked a friend who actually understands hg to help me with making hg work. I pity the fool that tries to use this option in a mixed hg and git environment when it's finished though.

@alsuren
Copy link
Contributor Author

alsuren commented Jan 13, 2018

I realised that actually I always want all changes that are included in HEAD and the working tree but not in the tree from $sinceCommit. This should stop users from relying on awkward constructs like HEAD^{/^Merge}, and allow them to specify something understandable like origin/master instead.

I will have a go at fixing the tests tomorrow.
I will also open another PR to make --lastCommit etc. imply --onlyChanged.
Now that I've changed the semantics, --changedFilesSinceCommit sounds even more terrible. Suggestions welcome.

@alsuren alsuren force-pushed the changed-files-refactor branch from 57a7181 to 933e33a Compare January 14, 2018 15:06
@alsuren alsuren changed the title WIP on jest --onlyChanged --changedFilesSinceCommit=$LAST_MERGE_COMMIT jest --changedFilesToContributeTo=origin/master Jan 14, 2018
@alsuren alsuren force-pushed the changed-files-refactor branch from c38eab0 to b637af5 Compare January 14, 2018 17:35
@alsuren
Copy link
Contributor Author

alsuren commented Jan 14, 2018

I fixed all the tests and conflicts, and cherry-picked #5307 (to preemptively resolve conflicts, because I wanted its functionality). I also settled on --changedFilesToContributeTo as a better name.

I think I'm pretty happy with the code at this point, so should be ready to review now, unless you'd prefer to review #5307 first (test failures look like permissions problems on the server, I think).

@SimenB
Copy link
Member

SimenB commented Jan 15, 2018

--changedFilesToContributeTo is pretty verbose, what about just --changedSince?

@cpojer
Copy link
Member

cpojer commented Jan 15, 2018

Closing this one in favor of the duplicate.

@cpojer cpojer closed this Jan 15, 2018
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants