-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
feat: CLI argument to filter tests by projects #8612
Conversation
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 [email protected]. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
Hey @yacinehmito, sorry about the lack of feedback here! Is there anything in particular you're stuck on? |
Sorry I did not come back to this. I wanted to have the API validated (i.e. the |
packages/jest-cli/src/cli/args.ts
Outdated
@@ -501,6 +501,13 @@ export const options = { | |||
'rare.', | |||
type: 'boolean' as 'boolean', | |||
}, | |||
runProjects: { |
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.
We can go with this for now, and bikeshed before landing 🙂
@yacinehmito wonderful, thank you! Not sure about the name, but that's easy to change once we're happy with the implementation 🙂 |
b067bc6
to
3ed9fff
Compare
Thank you very much for the fast response. I have an initial implementation working. I'd like a preliminary review to determine the following:
Also, the filtering relies on the (There is a bunch of |
Codecov Report
@@ Coverage Diff @@
## master #8612 +/- ##
==========================================
- Coverage 63.92% 63.77% -0.16%
==========================================
Files 293 297 +4
Lines 12496 12526 +30
Branches 3083 3092 +9
==========================================
Hits 7988 7988
- Misses 3863 3893 +30
Partials 645 645
Continue to review full report at Codecov.
|
3f6024c
to
7289f31
Compare
I managed to answer my own questions.
Very likely. The final name of the projects is given by
Turns out it doesn't matter. It's easy to include whitespace in the CLI (e.g.
Exiting because of one project has not been found doesn't seem like a good experience. If in the future we provide the ability to filter projects with globs we wouldn't throw because one glob hasn't had a match. Instead we could report on what was found so the user can compare. I have added this.
Nothing in particular. Jest will create a random name (an md5 hash, found it here). You just can't filter if you don't name the project. Other mattersThere is nothing that guarantees the unicity of project names. I don't know if this is something we'd like to check for. I've done it in my form just in case and included it just after About the |
Thanks for taking the time to really think this through! 👏
Inside
Perfect 🙂
Yeah, that seems reasonable.
Yeah, a separate PR for that sounds lovely!
I think having both |
I'll move the filtering and hold off until we know whether to use |
Allow me to kindle the conversation. I'll sum up the issue quickly: Context: We want to be able to specify which projects to run. However projects are currently identified in two ways:
Problem: When specifying which projects to filter on, we don't know whether we should use the Possible solutions (at the moment):
@SimenB suggests the second solution; and, if I may share my opinion, while it's an imperfect solution it's clearly the better one. @thymikee @jeysal Thoughts? (Sorry for pinging you, I'd just like to move forward with this) |
I'd go with |
@jeysal I agree. This is what we are using for in the watch plugin for selecting projects. https://github.com/jest-community/jest-watch-select-projects |
7289f31
to
f33e371
Compare
I just changed the code so that it uses The PR is ready for review. Also, let me know if you want a cleaner commit history. |
cf2a8ce
to
64768d6
Compare
We squash merge, so separate commits is preferred (especially as we review). I'll try to review this later today |
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.
Thanks, this turned out pretty small and contained! I'm also fine with the runProjects
name
const namesOfProjectsToRun = new Set<string>(argv.runProjects); | ||
return projectConfigs.filter(config => { | ||
const name = getProjectDisplayName(config); | ||
return name && namesOfProjectsToRun.has(name); |
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.
Should we print a warning if name
is not defined? If you're using this option you should (probably) also set a name for all your projects
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.
It is not. Doing it right now.
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 now addressed here: https://github.com/yacinehmito/jest/blob/1c35afb7a9e7265d9547f031b8ec6e1272824390/packages/jest-core/src/getSelectProjectsMessage.ts#L33
We can discuss the wording of the warning.
if (!argv.runProjects) { | ||
return projectConfigs; | ||
} | ||
const namesOfProjectsToRun = new Set<string>(argv.runProjects); |
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.
Might make sense to warn if the name here doesn't match any project
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.
is this and the feedback below addressed?
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.
We display: "No project to run". https://github.com/yacinehmito/jest/blob/1cd4d1a28f7d9898941005779c849d09482f7109/packages/jest-core/src/getProjectsRunningMessage.ts#L15
I think it's not enough; how do you think the warning should be worded?
Suggestion: "You provided values for --selectProjects but no projects were found matching the selection".
Might be too verbose, and I don't know if the 2nd second person form is suitable.
UPDATE: Changed the code with the suggestion above. Let's discuss wording.
|
||
import {Config} from '@jest/types'; | ||
|
||
export default function getProjectDisplayName( |
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 looks like https://github.com/facebook/jest/blob/d7a7b4294a4507030f86fe4f78e1790f53d0bda9/packages/jest-reporters/src/utils.ts#L18-L34 without the color. Can we share the code somehow?
Thinking about it, normalize
should probably spit out the object form with the default white
color, so we'd only have to deal with the one form inside jest
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.
That's what I was telling myself when I wrote this. However this bit of code is in jest-reporters
and I didn't know if or where I should move the code.
Leveraging normalize
makes more sense to me. I'll try that.
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 tried and I failed. I can't give a detailed account of the blockers because it was too long ago.
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.
Opened up #10010 for this btw, so we don't forget 🙂
Changed it to |
🤞 |
e2e/__tests__/selectProjects.test.ts
Outdated
}); | ||
|
||
describe('when Jest is started with `--selectProjects third-project`', () => { | ||
const result = runWithJson('select-projects', [ |
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.
can you stick this inside the test? describe
runs before tests start. can combine the 2 it
s, I guess, or stick the runWithJson
inside a beforeAll
e2e/__tests__/selectProjects.test.ts
Outdated
'third-project', | ||
]); | ||
it('does not run any tests', () => { | ||
expect(result.json.success).toBe(true); |
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.
should be false
, shouldn't it? If you pass a non-existing name, I think we should fail
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.
We do fail. Here it is true
because we also provide --passWithNoTests
. If we don't we can't get JSON output.
I'll change the tests to look for failure though.
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.
In the error cases we don't need JSON, we can just do the normal run (no json) and verify exitCode
and stderr
@SimenB It's ready for review. |
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 (argv.selectProjects) { | ||
const namesMissingWarning = getProjectNamesMissingWarning(configs); | ||
if (namesMissingWarning) { | ||
outputStream.write(namesMissingWarning); |
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.
we usually go with console.warn
for warnings, but I don't think it matters this much here
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.
console.warn
will always write the string to stdout
, whereas with outputStream we will write to either stdout
or stderr
depending on what is appropriate.
Here, if I replace outputStream.write
by console.warn
the tests will fail as they rely on the JSON output, and the JSON output can only be valid if all messages are written to stderr
instead of stdout
.
Thanks for a great PR and patience @yacinehmito! |
I can thank you for your patience just as much! Thanks a lot for allowing me to contribute to Jest. 🤗 |
Is this feature already a part of some release? |
Nope. You can look for it here: https://github.com/facebook/jest/releases |
…esolve-outside * upstream/master: (106 commits) docs: fix jest-diff example (jestjs#10067) Cleanup `displayName` type (jestjs#10049) docs: correct confusing filename in `enableAutomock` example (jestjs#10055) chore: minor optimize getTransformer (jestjs#10050) chore: fix TestUtils.ts to match the types (jestjs#10034) Minor test name typo fix (jestjs#10033) chore: upgrade to typescript 3.9 (jestjs#10031) feat: CLI argument to filter tests by projects (jestjs#8612) chore: bump `istanbul-lib-instrument` (jestjs#10009) feat: support config files exporting (`async`) `function`s (jestjs#10001) fix: add missing haste-map dep to jest-snapshot (jestjs#10008) 🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉 (jestjs#10000) Fix typo in dependency warning (jestjs#10006) chore: add missing comma (jestjs#9999) fix: Control no diff message color with diff options (jestjs#9997) fix(jest-jasmine2): fix Error message (jestjs#9990) docs: fix jest-object ids for docusaurs (jestjs#9994) docs: fix Configuration, JestPlatform and JestObjectAPI docs for 26 (jestjs#9985) Add migration notes for breaking changes (jestjs#9978) chore: fix date and heading in blog post (jestjs#9977) ...
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. |
Summary
This PR should close #7542.
The idea is to introduce a
runProjects
CLI argument so that a user can selectively run tests on provided projects.Test plan
An integration test ensures that the proper tests are run. It will be augmented as we discover new cases.
Current status
Currently, the pull request only has the definition for the new CLI argument and failing e2e tests.
Things to do:
runProjects
APIDetermine how to flag projects as running or not running.Not applicable given our approach.name
to identify the projects. A: We will not; we will usedisplayName
.I will update the description of this PR every time I make meaningful progress.
As this is the first time I'm contributing to jest, I might need some help to figure out where to find stuff.