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 --changedSince=origin/master #5312

Merged
merged 3 commits into from
Jan 19, 2018

Conversation

alsuren
Copy link
Contributor

@alsuren alsuren commented Jan 15, 2018

Summary

This is a duplicate of #5188 on the off-chance that the CI server's cache per-PR, and is therefore only poisoned for that PR.

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 --changedFilesToContributeTo=origin/master to test your entire feature branch, but not the whole project. It also tests only your changes if your branch has diverged from origin/master.

Test plan

~/src/jest$ yarn jest --listTests | wc -l
     220
~/src/jest$ yarn jest --listTests --changedFilesToContributeTo=origin/master | wc -l
      12

@alsuren alsuren changed the title jest --changedFilesToContributeTo=origin/master DUPLICATE: jest --changedFilesToContributeTo=origin/master Jan 15, 2018
@codecov-io
Copy link

codecov-io commented Jan 15, 2018

Codecov Report

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

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5312      +/-   ##
==========================================
- Coverage   61.32%   61.32%   -0.01%     
==========================================
  Files         205      205              
  Lines        6909     6914       +5     
  Branches        4        4              
==========================================
+ Hits         4237     4240       +3     
- Misses       2671     2673       +2     
  Partials        1        1
Impacted Files Coverage Δ
packages/jest-config/src/normalize.js 93.1% <ø> (ø) ⬆️
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-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 e8eb1d1...c95f4e3. Read the comment docs.

@SimenB
Copy link
Member

SimenB commented Jan 15, 2018

This needs a rebase.

Also, copying over my comment from the other PR.

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

@alsuren alsuren changed the title DUPLICATE: jest --changedFilesToContributeTo=origin/master jest --changedFilesToContributeTo=origin/master Jan 15, 2018
@alsuren alsuren changed the title jest --changedFilesToContributeTo=origin/master jest --changedSince=origin/master Jan 15, 2018
CHANGELOG.md Outdated
@@ -12,6 +12,9 @@
* `[jest-cli]` Make Jest exit without an error when no tests are found in the
case of `--lastCommit`, `--findRelatedTests`, or `--onlyChanged` options
having been passed to the CLI
* `[jest-cli]` `--changedSince`: allow selectively running tests for code
Copy link
Member

Choose a reason for hiding this comment

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

can you move this to just below master?

@@ -108,6 +108,12 @@ If you want to inspect the cache, use `--showConfig` and look at the
Runs tests related to the current changes and the changes made in the last
commit. Behaves similarly to `--onlyChanged`.

### `--changedSince`
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a "Since Jest 22.1.3+" or something?

Copy link
Contributor Author

@alsuren alsuren Jan 19, 2018

Choose a reason for hiding this comment

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

I said 22.2.0 because announcing that a feature is available since a patch release makes me uneasy. If it turns out that we release this feature without bumping the minor version then then ##### available in Jest **22.2.0+** is still not strictly a lie ;-)

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

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

Couple of docs nits, no biggie.

Thank you so much for adding this! Cool feature

@SimenB
Copy link
Member

SimenB commented Jan 19, 2018

Question: If I say --changedSince=HEAD and then make a commit, would this then know what changed, or do I have to do something like --changedSince=`git rev-parse HEAD` in order to be able to commit and still test all changes since I started?

@alsuren
Copy link
Contributor Author

alsuren commented Jan 19, 2018

Thanks for sticking with me as reviewer while I changed the spec and made a thousand rebases :D

If you say --changedSince=HEAD then git will re-evaluate what HEAD is every time, so you would indeed need to git rev-parse HEAD if you want the base point to stay put.

The flag is designed to so that you can just jest --watch --changedSince=origin/master and leave it running in the background forever (even when you switch what you're working on, or other people push things to origin/master) and it will always only test the changes that you're about to contribute.

If you just want to test the changes since the last time you did a git push, I think that --changedSince=@{upstream} should do the trick (according to man git rev-parse)

@jwbay
Copy link
Contributor

jwbay commented Feb 9, 2018

Just used this for the first time, and it's awesome. Fits my workflow perfectly. Thanks @alsuren!

@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.

6 participants